@threlte/rapier 3.0.0-next.13 → 3.0.0-next.15
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/Attractor/Attractor.svelte.d.ts +4 -34
- package/dist/components/Attractor/types.d.ts +30 -0
- package/dist/components/Attractor/types.js +1 -0
- package/dist/components/Colliders/{AutoColliders.svelte → AutoColliders/AutoColliders.svelte} +17 -10
- package/dist/components/Colliders/AutoColliders/AutoColliders.svelte.d.ts +23 -0
- package/dist/components/Colliders/AutoColliders/types.d.ts +74 -0
- package/dist/components/Colliders/AutoColliders/types.js +1 -0
- package/dist/components/Colliders/{Collider.svelte → Collider/Collider.svelte} +20 -16
- package/dist/components/Colliders/Collider/Collider.svelte.d.ts +21 -0
- package/dist/components/Colliders/Collider/types.d.ts +83 -0
- package/dist/components/Colliders/Collider/types.js +1 -0
- package/dist/components/CollisionGroups/CollisionGroups.svelte +4 -1
- package/dist/components/CollisionGroups/CollisionGroups.svelte.d.ts +17 -33
- package/dist/components/CollisionGroups/types.d.ts +19 -0
- package/dist/components/CollisionGroups/types.js +1 -0
- package/dist/components/Debug/Debug.svelte +5 -5
- package/dist/components/Debug/Debug.svelte.d.ts +4 -7
- package/dist/components/Debug/types.d.ts +3 -0
- package/dist/components/Debug/types.js +1 -0
- package/dist/components/RigidBody/RigidBody.svelte.d.ts +4 -102
- package/dist/components/RigidBody/types.d.ts +85 -0
- package/dist/components/RigidBody/types.js +1 -0
- package/dist/components/World/InnerWorld.svelte.d.ts +4 -15
- package/dist/components/World/World.svelte.d.ts +4 -49
- package/dist/components/World/types.d.ts +32 -0
- package/dist/components/World/types.js +1 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -4
- package/dist/lib/useCreateEvent.d.ts +2 -2
- package/dist/lib/useCreateEvent.js +3 -5
- package/dist/types/types.d.ts +3 -4
- package/package.json +4 -4
- package/dist/components/Colliders/AutoColliders.svelte.d.ts +0 -84
- package/dist/components/Colliders/Collider.svelte.d.ts +0 -109
- package/dist/recipes/BasicPlayerController.svelte +0 -142
- package/dist/recipes/BasicPlayerController.svelte.d.ts +0 -29
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { RigidBody as RapierRigidBody } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { type Snippet } from 'svelte';
|
|
3
|
+
import type { Euler, Vector3 } from 'three';
|
|
4
|
+
import type { RigidBodyTypeString } from '../../lib/parseRigidBodyType';
|
|
5
|
+
import type { CreateEvent, RigidBodyEvents } from '../../types/types';
|
|
6
|
+
export type Boolean3Array = [x: boolean, y: boolean, z: boolean];
|
|
7
|
+
export type RigidBodyProps = CreateEvent<RapierRigidBody> & RigidBodyEvents & {
|
|
8
|
+
rigidBody?: RapierRigidBody | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Specify the type of this rigid body
|
|
11
|
+
*/
|
|
12
|
+
type?: RigidBodyTypeString;
|
|
13
|
+
/** Whether or not this body can sleep.
|
|
14
|
+
* default: true
|
|
15
|
+
*/
|
|
16
|
+
canSleep?: boolean;
|
|
17
|
+
/** The linear velocity of this body.
|
|
18
|
+
* default: zero velocity
|
|
19
|
+
*/
|
|
20
|
+
linearVelocity?: Parameters<Vector3['set']>;
|
|
21
|
+
/** The angular velocity of this body.
|
|
22
|
+
* Default: zero velocity.
|
|
23
|
+
*/
|
|
24
|
+
angularVelocity?: Parameters<Euler['set']>;
|
|
25
|
+
/**
|
|
26
|
+
* The scaling factor applied to the gravity affecting the rigid-body.
|
|
27
|
+
* Default: 1.0
|
|
28
|
+
*/
|
|
29
|
+
gravityScale?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Whether or not Continous Collision Detection is enabled for this rigid-body.
|
|
32
|
+
* https://rapier.rs/docs/user_guides/javascript/rigid_bodies#continuous-collision-detection
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
ccd?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Locks all rotations that would have resulted from forces on the created rigid-body.
|
|
38
|
+
*/
|
|
39
|
+
lockRotations?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Locks all translations that would have resulted from forces on the created rigid-body.
|
|
42
|
+
*/
|
|
43
|
+
lockTranslations?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Allow rotation of this rigid-body only along specific axes.
|
|
46
|
+
*/
|
|
47
|
+
enabledRotations?: Boolean3Array;
|
|
48
|
+
/**
|
|
49
|
+
* Allow translations of this rigid-body only along specific axes.
|
|
50
|
+
*/
|
|
51
|
+
enabledTranslations?: Boolean3Array;
|
|
52
|
+
/**
|
|
53
|
+
* Dominance is a non-realistic, but sometimes useful, feature.
|
|
54
|
+
* It can be used to make one rigid-body immune to forces
|
|
55
|
+
* originating from contacts with some other bodies.
|
|
56
|
+
*
|
|
57
|
+
* Number in the range -127 to 127, default is 0
|
|
58
|
+
*/
|
|
59
|
+
dominance?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Damping lets you slow down a rigid-body automatically. This can be used to
|
|
62
|
+
* achieve a wide variety of effects like fake air friction. Larger values of
|
|
63
|
+
* damping coefficients lead to a stronger slow-downs. Their default
|
|
64
|
+
* values are 0.0 (no damping at all).
|
|
65
|
+
*/
|
|
66
|
+
linearDamping?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Damping lets you slow down a rigid-body automatically. This can be used to
|
|
69
|
+
* achieve a wide variety of effects like fake air friction. Larger values of
|
|
70
|
+
* damping coefficients lead to a stronger slow-downs. Their default
|
|
71
|
+
* values are 0.0 (no damping at all).
|
|
72
|
+
*/
|
|
73
|
+
angularDamping?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Set the rigidBody as enabled or disabled.
|
|
76
|
+
*/
|
|
77
|
+
enabled?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* An arbitrary user-defined object associated with this rigid-body.
|
|
80
|
+
*/
|
|
81
|
+
userData?: Record<string, any>;
|
|
82
|
+
children?: Snippet<[{
|
|
83
|
+
rigidBody: RapierRigidBody;
|
|
84
|
+
}]>;
|
|
85
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import type { WorldProps } from './
|
|
3
|
-
declare const
|
|
4
|
-
|
|
5
|
-
events: {
|
|
6
|
-
[evt: string]: CustomEvent<any>;
|
|
7
|
-
};
|
|
8
|
-
slots: {};
|
|
9
|
-
};
|
|
10
|
-
export type InnerWorldProps = typeof __propDef.props;
|
|
11
|
-
export type InnerWorldEvents = typeof __propDef.events;
|
|
12
|
-
export type InnerWorldSlots = typeof __propDef.slots;
|
|
13
|
-
export default class InnerWorld extends SvelteComponent<InnerWorldProps, InnerWorldEvents, InnerWorldSlots> {
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import type { WorldProps } from './types';
|
|
3
|
+
declare const InnerWorld: import("svelte").Component<WorldProps, {}, "">;
|
|
4
|
+
export default InnerWorld;
|
|
@@ -1,49 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
RawDebugRenderPipeline,
|
|
6
|
-
RawImpulseJointSet,
|
|
7
|
-
RawIntegrationParameters,
|
|
8
|
-
RawIslandManager,
|
|
9
|
-
RawMultibodyJointSet,
|
|
10
|
-
RawNarrowPhase,
|
|
11
|
-
RawPhysicsPipeline,
|
|
12
|
-
RawQueryPipeline,
|
|
13
|
-
RawRigidBodySet,
|
|
14
|
-
RawSerializationPipeline
|
|
15
|
-
} from '@dimforge/rapier3d-compat/raw'
|
|
16
|
-
import { SvelteComponent, type Snippet } from 'svelte'
|
|
17
|
-
import type { Vector3 } from 'three'
|
|
18
|
-
import type { Key, Stage } from '@threlte/core'
|
|
19
|
-
|
|
20
|
-
export type WorldProps = {
|
|
21
|
-
framerate?: number | 'varying'
|
|
22
|
-
autoStart?: boolean
|
|
23
|
-
gravity?: Parameters<Vector3['set']>
|
|
24
|
-
rawIntegrationParameters?: RawIntegrationParameters
|
|
25
|
-
rawIslands?: RawIslandManager
|
|
26
|
-
rawBroadPhase?: RawBroadPhase
|
|
27
|
-
rawNarrowPhase?: RawNarrowPhase
|
|
28
|
-
rawBodies?: RawRigidBodySet
|
|
29
|
-
rawColliders?: RawColliderSet
|
|
30
|
-
rawImpulseJoints?: RawImpulseJointSet
|
|
31
|
-
rawMultibodyJoints?: RawMultibodyJointSet
|
|
32
|
-
rawCCDSolver?: RawCCDSolver
|
|
33
|
-
rawQueryPipeline?: RawQueryPipeline
|
|
34
|
-
rawPhysicsPipeline?: RawPhysicsPipeline
|
|
35
|
-
rawSerializationPipeline?: RawSerializationPipeline
|
|
36
|
-
rawDebugRenderPipeline?: RawDebugRenderPipeline
|
|
37
|
-
simulationStageOptions?: {
|
|
38
|
-
before?: (Key | Stage) | (Key | Stage)[]
|
|
39
|
-
after?: (Key | Stage) | (Key | Stage)[]
|
|
40
|
-
}
|
|
41
|
-
synchronizationStageOptions?: {
|
|
42
|
-
before?: (Key | Stage) | (Key | Stage)[]
|
|
43
|
-
after?: (Key | Stage) | (Key | Stage)[]
|
|
44
|
-
}
|
|
45
|
-
children?: Snippet
|
|
46
|
-
fallback?: Snippet<[error: any]>
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default class World extends SvelteComponent<WorldProps> {}
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import type { WorldProps } from './types';
|
|
3
|
+
declare const World: import("svelte").Component<WorldProps, {}, "">;
|
|
4
|
+
export default World;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RawBroadPhase, RawCCDSolver, RawColliderSet, RawDebugRenderPipeline, RawImpulseJointSet, RawIntegrationParameters, RawIslandManager, RawMultibodyJointSet, RawNarrowPhase, RawPhysicsPipeline, RawQueryPipeline, RawRigidBodySet, RawSerializationPipeline } from '@dimforge/rapier3d-compat/raw';
|
|
2
|
+
import type { Key, Stage } from '@threlte/core';
|
|
3
|
+
import { type Snippet } from 'svelte';
|
|
4
|
+
import type { Vector3 } from 'three';
|
|
5
|
+
export type WorldProps = {
|
|
6
|
+
framerate?: number | 'varying';
|
|
7
|
+
autoStart?: boolean;
|
|
8
|
+
gravity?: Parameters<Vector3['set']>;
|
|
9
|
+
rawIntegrationParameters?: RawIntegrationParameters;
|
|
10
|
+
rawIslands?: RawIslandManager;
|
|
11
|
+
rawBroadPhase?: RawBroadPhase;
|
|
12
|
+
rawNarrowPhase?: RawNarrowPhase;
|
|
13
|
+
rawBodies?: RawRigidBodySet;
|
|
14
|
+
rawColliders?: RawColliderSet;
|
|
15
|
+
rawImpulseJoints?: RawImpulseJointSet;
|
|
16
|
+
rawMultibodyJoints?: RawMultibodyJointSet;
|
|
17
|
+
rawCCDSolver?: RawCCDSolver;
|
|
18
|
+
rawQueryPipeline?: RawQueryPipeline;
|
|
19
|
+
rawPhysicsPipeline?: RawPhysicsPipeline;
|
|
20
|
+
rawSerializationPipeline?: RawSerializationPipeline;
|
|
21
|
+
rawDebugRenderPipeline?: RawDebugRenderPipeline;
|
|
22
|
+
simulationStageOptions?: {
|
|
23
|
+
before?: (Key | Stage) | (Key | Stage)[];
|
|
24
|
+
after?: (Key | Stage) | (Key | Stage)[];
|
|
25
|
+
};
|
|
26
|
+
synchronizationStageOptions?: {
|
|
27
|
+
before?: (Key | Stage) | (Key | Stage)[];
|
|
28
|
+
after?: (Key | Stage) | (Key | Stage)[];
|
|
29
|
+
};
|
|
30
|
+
children?: Snippet;
|
|
31
|
+
fallback?: Snippet<[error: any]>;
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -9,10 +9,9 @@ export { useJoint } from './hooks/useJoint';
|
|
|
9
9
|
export { default as World } from './components/World/World.svelte';
|
|
10
10
|
export { default as RigidBody } from './components/RigidBody/RigidBody.svelte';
|
|
11
11
|
export { default as Debug } from './components/Debug/Debug.svelte';
|
|
12
|
-
export { default as Collider } from './components/Colliders/Collider.svelte';
|
|
13
|
-
export { default as AutoColliders } from './components/Colliders/AutoColliders.svelte';
|
|
12
|
+
export { default as Collider } from './components/Colliders/Collider/Collider.svelte';
|
|
13
|
+
export { default as AutoColliders } from './components/Colliders/AutoColliders/AutoColliders.svelte';
|
|
14
14
|
export { default as CollisionGroups } from './components/CollisionGroups/CollisionGroups.svelte';
|
|
15
15
|
export { default as Attractor } from './components/Attractor/Attractor.svelte';
|
|
16
16
|
export { computeBitMask } from './lib/computeBitMask';
|
|
17
|
-
export {
|
|
18
|
-
export type { CollisionGroupsBitMask, AutoCollidersShapes, ColliderEventDispatcher, ColliderShapes, RapierContext, RigidBodyEventDispatcher, CollisionEnterEvent, CollisionExitEvent, SensorEnterEvent, SensorExitEvent, ContactEvent, GravityType } from './types/types';
|
|
17
|
+
export type { CollisionGroupsBitMask, AutoCollidersShapes, ColliderShapes, RapierContext, CollisionEnterEvent, CollisionExitEvent, SensorEnterEvent, SensorExitEvent, ContactEvent, GravityType, CreateEvent, Framerate } from './types/types';
|
package/dist/index.js
CHANGED
|
@@ -12,11 +12,9 @@ export { useJoint } from './hooks/useJoint';
|
|
|
12
12
|
export { default as World } from './components/World/World.svelte';
|
|
13
13
|
export { default as RigidBody } from './components/RigidBody/RigidBody.svelte';
|
|
14
14
|
export { default as Debug } from './components/Debug/Debug.svelte';
|
|
15
|
-
export { default as Collider } from './components/Colliders/Collider.svelte';
|
|
16
|
-
export { default as AutoColliders } from './components/Colliders/AutoColliders.svelte';
|
|
15
|
+
export { default as Collider } from './components/Colliders/Collider/Collider.svelte';
|
|
16
|
+
export { default as AutoColliders } from './components/Colliders/AutoColliders/AutoColliders.svelte';
|
|
17
17
|
export { default as CollisionGroups } from './components/CollisionGroups/CollisionGroups.svelte';
|
|
18
18
|
export { default as Attractor } from './components/Attractor/Attractor.svelte';
|
|
19
19
|
// lib
|
|
20
20
|
export { computeBitMask } from './lib/computeBitMask';
|
|
21
|
-
// recipes
|
|
22
|
-
export { default as BasicPlayerController } from './recipes/BasicPlayerController.svelte';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const useCreateEvent: <T>(oncreate?:
|
|
1
|
+
import type { CreateEvent } from '../types/types';
|
|
2
|
+
export declare const useCreateEvent: <T>(oncreate?: CreateEvent<T>['oncreate']) => {
|
|
3
3
|
updateRef: (newRef: T) => void;
|
|
4
4
|
};
|
|
@@ -7,13 +7,11 @@ export const useCreateEvent = (oncreate) => {
|
|
|
7
7
|
cleanupFunctions.forEach((cleanup) => cleanup());
|
|
8
8
|
// clear the cleanup functions array
|
|
9
9
|
cleanupFunctions.length = 0;
|
|
10
|
-
const cleanup = (callback) => {
|
|
11
|
-
// add cleanup function to array
|
|
12
|
-
cleanupFunctions.push(callback);
|
|
13
|
-
};
|
|
14
10
|
if (ref === undefined)
|
|
15
11
|
return;
|
|
16
|
-
oncreate?.(
|
|
12
|
+
const cleanup = oncreate?.(ref);
|
|
13
|
+
if (cleanup)
|
|
14
|
+
cleanupFunctions.push(cleanup);
|
|
17
15
|
};
|
|
18
16
|
const updateRef = (newRef) => {
|
|
19
17
|
ref = newRef;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -6,11 +6,10 @@ import type { Readable, Writable } from 'svelte/store';
|
|
|
6
6
|
import type { Object3D } from 'three';
|
|
7
7
|
export type ColliderShapes = 'ball' | 'capsule' | 'segment' | 'triangle' | 'roundTriangle' | 'polyline' | 'trimesh' | 'cuboid' | 'roundCuboid' | 'heightfield' | 'cylinder' | 'roundCylinder' | 'cone' | 'roundCone' | 'convexHull' | 'convexMesh' | 'roundConvexHull' | 'roundConvexMesh';
|
|
8
8
|
export type AutoCollidersShapes = 'cuboid' | 'ball' | 'trimesh' | 'convexHull' | 'capsule';
|
|
9
|
+
export type CreateEvent<T> = {
|
|
10
|
+
oncreate?: (ref: T) => void | (() => void);
|
|
11
|
+
};
|
|
9
12
|
export type ColliderEvents = {
|
|
10
|
-
oncreate?: (event: {
|
|
11
|
-
ref: Collider;
|
|
12
|
-
cleanup: (callback: () => void) => void;
|
|
13
|
-
}) => void;
|
|
14
13
|
oncollisionenter?: (event: {
|
|
15
14
|
targetCollider: Collider;
|
|
16
15
|
targetRigidBody: RigidBody | null;
|
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.15",
|
|
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",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@dimforge/rapier3d-compat": "^0.14.0",
|
|
9
9
|
"@sveltejs/adapter-auto": "^3.2.0",
|
|
10
10
|
"@sveltejs/kit": "^2.7.2",
|
|
11
|
-
"@sveltejs/package": "^2.3.
|
|
11
|
+
"@sveltejs/package": "^2.3.7",
|
|
12
12
|
"@sveltejs/vite-plugin-svelte": "^3.1.0",
|
|
13
13
|
"@types/node": "^20.12.7",
|
|
14
14
|
"@types/three": "^0.169.0",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"prettier-plugin-svelte": "^3.2.2",
|
|
23
23
|
"publint": "^0.2.7",
|
|
24
24
|
"rimraf": "^5.0.5",
|
|
25
|
-
"svelte": "^5.
|
|
25
|
+
"svelte": "^5.1.6",
|
|
26
26
|
"svelte-check": "^3.6.9",
|
|
27
27
|
"svelte-preprocess": "^5.1.3",
|
|
28
28
|
"svelte2tsx": "^0.7.6",
|
|
@@ -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.23"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@dimforge/rapier3d-compat": ">=0.14",
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { CoefficientCombineRule, Collider } from '@dimforge/rapier3d-compat'
|
|
2
|
-
import { SvelteComponent, type Snippet } from 'svelte'
|
|
3
|
-
import type { Euler, Vector3 } from 'three'
|
|
4
|
-
import type { AutoCollidersShapes, ColliderEvents } from '../../types/types'
|
|
5
|
-
|
|
6
|
-
// ------------------ BASE ------------------
|
|
7
|
-
|
|
8
|
-
type BaseProps = {
|
|
9
|
-
shape?: AutoCollidersShapes
|
|
10
|
-
restitution?: number
|
|
11
|
-
restitutionCombineRule?: CoefficientCombineRule
|
|
12
|
-
friction?: number
|
|
13
|
-
frictionCombineRule?: CoefficientCombineRule
|
|
14
|
-
sensor?: boolean
|
|
15
|
-
colliders?: Collider[]
|
|
16
|
-
contactForceEventThreshold?: number
|
|
17
|
-
|
|
18
|
-
refresh?: () => void
|
|
19
|
-
|
|
20
|
-
oncreate?: () => void
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// ------------------ MASS ------------------
|
|
24
|
-
|
|
25
|
-
type Density = {
|
|
26
|
-
density: number
|
|
27
|
-
|
|
28
|
-
mass?: never
|
|
29
|
-
centerOfMass?: never
|
|
30
|
-
principalAngularInertia?: never
|
|
31
|
-
angularInertiaLocalFrame?: never
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type Mass = {
|
|
35
|
-
mass: number
|
|
36
|
-
density?: never
|
|
37
|
-
centerOfMass?: never
|
|
38
|
-
principalAngularInertia?: never
|
|
39
|
-
angularInertiaLocalFrame?: never
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type MassProperties = {
|
|
43
|
-
mass: number
|
|
44
|
-
centerOfMass: Parameters<Vector3['set']>
|
|
45
|
-
principalAngularInertia: Parameters<Vector3['set']>
|
|
46
|
-
angularInertiaLocalFrame: Parameters<Euler['set']>
|
|
47
|
-
density?: never
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
type NoMassProperties = {
|
|
51
|
-
density?: never
|
|
52
|
-
mass?: never
|
|
53
|
-
centerOfMass?: never
|
|
54
|
-
principalAngularInertia?: never
|
|
55
|
-
angularInertiaLocalFrame?: never
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type MassDef = Density | Mass | MassProperties | NoMassProperties
|
|
59
|
-
|
|
60
|
-
type MassProps<TMassDef extends MassDef> = TMassDef extends Density
|
|
61
|
-
? Density
|
|
62
|
-
: TMassDef extends MassProperties
|
|
63
|
-
? MassProperties
|
|
64
|
-
: TMassDef extends Mass
|
|
65
|
-
? Mass
|
|
66
|
-
: NoMassProperties
|
|
67
|
-
|
|
68
|
-
// ------------------ COLLIDER ------------------
|
|
69
|
-
|
|
70
|
-
export type AutoCollidersProps<TMassDef extends MassDef> = BaseProps &
|
|
71
|
-
MassProps<TMassDef> & {
|
|
72
|
-
children?: Snippet<
|
|
73
|
-
[
|
|
74
|
-
{
|
|
75
|
-
colliders: Collider[]
|
|
76
|
-
refresh: () => void
|
|
77
|
-
}
|
|
78
|
-
]
|
|
79
|
-
>
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export default class AutoColliders<TMassDef extends MassDef> extends SvelteComponent<
|
|
83
|
-
AutoCollidersProps<TMassDef>
|
|
84
|
-
> {}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CoefficientCombineRule,
|
|
3
|
-
Collider as RapierCollider,
|
|
4
|
-
ColliderDesc
|
|
5
|
-
} from '@dimforge/rapier3d-compat'
|
|
6
|
-
import { SvelteComponent, type Snippet } from 'svelte'
|
|
7
|
-
import type { Euler, Vector3 } from 'three'
|
|
8
|
-
import type { ColliderEvents } from '../../types/types'
|
|
9
|
-
|
|
10
|
-
// ------------------ BASE ------------------
|
|
11
|
-
|
|
12
|
-
type Type = 'static' | 'dynamic'
|
|
13
|
-
|
|
14
|
-
type BaseProps = {
|
|
15
|
-
type?: Type
|
|
16
|
-
restitution?: number
|
|
17
|
-
restitutionCombineRule?: CoefficientCombineRule
|
|
18
|
-
friction?: number
|
|
19
|
-
frictionCombineRule?: CoefficientCombineRule
|
|
20
|
-
sensor?: boolean
|
|
21
|
-
collider?: RapierCollider
|
|
22
|
-
contactForceEventThreshold?: number
|
|
23
|
-
refresh?: () => void
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// ------------------ SHAPE ------------------
|
|
27
|
-
|
|
28
|
-
export type Shape =
|
|
29
|
-
| 'ball'
|
|
30
|
-
| 'capsule'
|
|
31
|
-
| 'segment'
|
|
32
|
-
| 'triangle'
|
|
33
|
-
| 'roundTriangle'
|
|
34
|
-
| 'polyline'
|
|
35
|
-
| 'trimesh'
|
|
36
|
-
| 'cuboid'
|
|
37
|
-
| 'roundCuboid'
|
|
38
|
-
| 'heightfield'
|
|
39
|
-
| 'cylinder'
|
|
40
|
-
| 'roundCylinder'
|
|
41
|
-
| 'cone'
|
|
42
|
-
| 'roundCone'
|
|
43
|
-
| 'convexHull'
|
|
44
|
-
| 'convexMesh'
|
|
45
|
-
| 'roundConvexHull'
|
|
46
|
-
| 'roundConvexMesh'
|
|
47
|
-
|
|
48
|
-
type Args<TShape extends Shape> = Parameters<(typeof ColliderDesc)[TShape]>
|
|
49
|
-
|
|
50
|
-
type ShapeProps<TShape extends Shape> = {
|
|
51
|
-
shape: TShape
|
|
52
|
-
args: Args<TShape>
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ------------------ MASS ------------------
|
|
56
|
-
|
|
57
|
-
type Density = {
|
|
58
|
-
density: number
|
|
59
|
-
mass?: never
|
|
60
|
-
centerOfMass?: never
|
|
61
|
-
principalAngularInertia?: never
|
|
62
|
-
angularInertiaLocalFrame?: never
|
|
63
|
-
}
|
|
64
|
-
type Mass = {
|
|
65
|
-
mass: number
|
|
66
|
-
density?: never
|
|
67
|
-
centerOfMass?: never
|
|
68
|
-
principalAngularInertia?: never
|
|
69
|
-
angularInertiaLocalFrame?: never
|
|
70
|
-
}
|
|
71
|
-
type MassProperties = {
|
|
72
|
-
mass: number
|
|
73
|
-
centerOfMass: Parameters<Vector3['set']>
|
|
74
|
-
principalAngularInertia: Parameters<Vector3['set']>
|
|
75
|
-
angularInertiaLocalFrame: Parameters<Euler['set']>
|
|
76
|
-
density?: never
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
type NoMassProperties = {
|
|
80
|
-
density?: never
|
|
81
|
-
mass?: never
|
|
82
|
-
centerOfMass?: never
|
|
83
|
-
principalAngularInertia?: never
|
|
84
|
-
angularInertiaLocalFrame?: never
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export type MassDef = Density | Mass | MassProperties | NoMassProperties
|
|
88
|
-
|
|
89
|
-
type MassProps<TMassDef extends MassDef> = TMassDef extends Density
|
|
90
|
-
? Density
|
|
91
|
-
: TMassDef extends MassProperties
|
|
92
|
-
? MassProperties
|
|
93
|
-
: TMassDef extends Mass
|
|
94
|
-
? Mass
|
|
95
|
-
: NoMassProperties
|
|
96
|
-
|
|
97
|
-
// ------------------ COLLIDER ------------------
|
|
98
|
-
|
|
99
|
-
export type ColliderProps<TShape extends Shape, TMassDef extends MassDef> = BaseProps &
|
|
100
|
-
ColliderEvents &
|
|
101
|
-
ShapeProps<TShape> &
|
|
102
|
-
MassProps<TMassDef> & {
|
|
103
|
-
children?: Snippet<[{ collider?: RapierCollider }]>
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export default class Collider<
|
|
107
|
-
TShape extends Shape,
|
|
108
|
-
TMassDef extends MassDef
|
|
109
|
-
> extends SvelteComponent<ColliderProps<TShape, TMassDef>> {}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
<script lang="ts">import { T, useTask } from '@threlte/core';
|
|
2
|
-
import { Vector2, Vector3 } from 'three';
|
|
3
|
-
import Collider from '../components/Colliders/Collider.svelte';
|
|
4
|
-
import CollisionGroups from '../components/CollisionGroups/CollisionGroups.svelte';
|
|
5
|
-
import RigidBody from '../components/RigidBody/RigidBody.svelte';
|
|
6
|
-
export let position = undefined;
|
|
7
|
-
export let height = 1.7;
|
|
8
|
-
export let radius = 0.3;
|
|
9
|
-
export let speed = 1;
|
|
10
|
-
export let jumpStrength = 3;
|
|
11
|
-
export let playerCollisionGroups = [0];
|
|
12
|
-
export let groundCollisionGroups = [15];
|
|
13
|
-
export let ongroundenter = undefined;
|
|
14
|
-
export let ongroundexit = undefined;
|
|
15
|
-
let rigidBody;
|
|
16
|
-
const keys = {
|
|
17
|
-
up: false,
|
|
18
|
-
down: false,
|
|
19
|
-
left: false,
|
|
20
|
-
right: false
|
|
21
|
-
};
|
|
22
|
-
const t = new Vector3();
|
|
23
|
-
const t2 = new Vector2();
|
|
24
|
-
let grounded = false;
|
|
25
|
-
let groundsSensored = 0;
|
|
26
|
-
$: {
|
|
27
|
-
if (groundsSensored === 0)
|
|
28
|
-
grounded = false;
|
|
29
|
-
else
|
|
30
|
-
grounded = true;
|
|
31
|
-
}
|
|
32
|
-
$: grounded ? ongroundenter?.() : ongroundexit?.();
|
|
33
|
-
const { start } = useTask(() => {
|
|
34
|
-
t.set(0, 0, 0);
|
|
35
|
-
if (keys.down)
|
|
36
|
-
t.x += 1;
|
|
37
|
-
if (keys.up)
|
|
38
|
-
t.x -= 1;
|
|
39
|
-
if (keys.left)
|
|
40
|
-
t.z += 1;
|
|
41
|
-
if (keys.right)
|
|
42
|
-
t.z -= 1;
|
|
43
|
-
const l = t.length();
|
|
44
|
-
const xzLength = t2.set(t.x, t.z).length();
|
|
45
|
-
if (l > 0)
|
|
46
|
-
t.divideScalar(l).multiplyScalar(speed);
|
|
47
|
-
if (xzLength > 0) {
|
|
48
|
-
rigidBody.resetForces(true);
|
|
49
|
-
rigidBody.resetTorques(true);
|
|
50
|
-
}
|
|
51
|
-
const linVel = rigidBody.linvel();
|
|
52
|
-
t.y = linVel.y;
|
|
53
|
-
rigidBody.setLinvel(t, true);
|
|
54
|
-
});
|
|
55
|
-
$: if (rigidBody)
|
|
56
|
-
start();
|
|
57
|
-
const onKeyDown = (e) => {
|
|
58
|
-
switch (e.key.toLowerCase()) {
|
|
59
|
-
case 's':
|
|
60
|
-
case 'arrowdown':
|
|
61
|
-
keys.down = true;
|
|
62
|
-
break;
|
|
63
|
-
case 'w':
|
|
64
|
-
case 'arrowup':
|
|
65
|
-
keys.up = true;
|
|
66
|
-
break;
|
|
67
|
-
case 'a':
|
|
68
|
-
case 'arrowleft':
|
|
69
|
-
keys.left = true;
|
|
70
|
-
break;
|
|
71
|
-
case 'd':
|
|
72
|
-
case 'arrowright':
|
|
73
|
-
keys.right = true;
|
|
74
|
-
break;
|
|
75
|
-
case ' ':
|
|
76
|
-
if (!rigidBody || !grounded)
|
|
77
|
-
break;
|
|
78
|
-
rigidBody.applyImpulse({ x: 0, y: jumpStrength, z: 0 }, true);
|
|
79
|
-
default:
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const onKeyUp = (e) => {
|
|
84
|
-
switch (e.key.toLowerCase()) {
|
|
85
|
-
case 's':
|
|
86
|
-
case 'arrowdown':
|
|
87
|
-
keys.down = false;
|
|
88
|
-
break;
|
|
89
|
-
case 'w':
|
|
90
|
-
case 'arrowup':
|
|
91
|
-
keys.up = false;
|
|
92
|
-
break;
|
|
93
|
-
case 'a':
|
|
94
|
-
case 'arrowleft':
|
|
95
|
-
keys.left = false;
|
|
96
|
-
break;
|
|
97
|
-
case 'd':
|
|
98
|
-
case 'arrowright':
|
|
99
|
-
keys.right = false;
|
|
100
|
-
break;
|
|
101
|
-
default:
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
</script>
|
|
106
|
-
|
|
107
|
-
<svelte:window
|
|
108
|
-
on:keydown|preventDefault={onKeyDown}
|
|
109
|
-
on:keyup|preventDefault={onKeyUp}
|
|
110
|
-
/>
|
|
111
|
-
|
|
112
|
-
<T.Group {position}>
|
|
113
|
-
<RigidBody
|
|
114
|
-
dominance={127}
|
|
115
|
-
enabledRotations={[false, false, false]}
|
|
116
|
-
bind:rigidBody
|
|
117
|
-
type={'dynamic'}
|
|
118
|
-
>
|
|
119
|
-
<CollisionGroups groups={playerCollisionGroups}>
|
|
120
|
-
<Collider
|
|
121
|
-
shape={'capsule'}
|
|
122
|
-
args={[height / 2 - radius, radius]}
|
|
123
|
-
/>
|
|
124
|
-
</CollisionGroups>
|
|
125
|
-
|
|
126
|
-
<CollisionGroups groups={groundCollisionGroups}>
|
|
127
|
-
<T.Group position={[0, -height / 2 + radius, 0]}>
|
|
128
|
-
<Collider
|
|
129
|
-
sensor
|
|
130
|
-
onsensorenter={() => (groundsSensored += 1)}
|
|
131
|
-
onsensorexit={() => (groundsSensored -= 1)}
|
|
132
|
-
shape={'ball'}
|
|
133
|
-
args={[radius * 1.2]}
|
|
134
|
-
/>
|
|
135
|
-
</T.Group>
|
|
136
|
-
</CollisionGroups>
|
|
137
|
-
|
|
138
|
-
<T.Group position.y={-height / 2}>
|
|
139
|
-
<slot />
|
|
140
|
-
</T.Group>
|
|
141
|
-
</RigidBody>
|
|
142
|
-
</T.Group>
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
import { Vector3 } from 'three';
|
|
3
|
-
import type { CollisionGroupsBitMask } from '../types/types';
|
|
4
|
-
declare const __propDef: {
|
|
5
|
-
props: {
|
|
6
|
-
position?: Parameters<Vector3['set']> | undefined;
|
|
7
|
-
height?: number | undefined;
|
|
8
|
-
radius?: number | undefined;
|
|
9
|
-
speed?: number | undefined;
|
|
10
|
-
jumpStrength?: number | undefined;
|
|
11
|
-
playerCollisionGroups?: CollisionGroupsBitMask | undefined;
|
|
12
|
-
groundCollisionGroups?: CollisionGroupsBitMask | undefined;
|
|
13
|
-
ongroundenter?: (() => void) | undefined;
|
|
14
|
-
ongroundexit?: (() => void) | undefined;
|
|
15
|
-
children?: import("svelte").Snippet<[]> | undefined;
|
|
16
|
-
};
|
|
17
|
-
events: {
|
|
18
|
-
[evt: string]: CustomEvent<any>;
|
|
19
|
-
};
|
|
20
|
-
slots: {
|
|
21
|
-
default: {};
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export type BasicPlayerControllerProps = typeof __propDef.props;
|
|
25
|
-
export type BasicPlayerControllerEvents = typeof __propDef.events;
|
|
26
|
-
export type BasicPlayerControllerSlots = typeof __propDef.slots;
|
|
27
|
-
export default class BasicPlayerController extends SvelteComponent<BasicPlayerControllerProps, BasicPlayerControllerEvents, BasicPlayerControllerSlots> {
|
|
28
|
-
}
|
|
29
|
-
export {};
|