@kite3d/engine 0.15.0
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/authoring.d.ts +54 -0
- package/dist/authoring.js +165 -0
- package/dist/authoring.js.map +1 -0
- package/dist/authoringValidation.d.ts +110 -0
- package/dist/authoringValidation.js +488 -0
- package/dist/authoringValidation.js.map +1 -0
- package/dist/defaults.d.ts +2 -0
- package/dist/fileTypes.d.ts +5 -0
- package/dist/fileTypes.js +51 -0
- package/dist/fileTypes.js.map +1 -0
- package/dist/importMap.d.ts +15 -0
- package/dist/importMap.js +62 -0
- package/dist/importMap.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +2756 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations.js +5 -0
- package/dist/migrations.js.map +1 -0
- package/dist/paths.d.ts +9 -0
- package/dist/paths.js +13 -0
- package/dist/paths.js.map +1 -0
- package/dist/plugins/GeneratorComponent.d.ts +40 -0
- package/dist/plugins/HtmlUiComponent.d.ts +52 -0
- package/dist/plugins/HtmlUiComponent.example.d.ts +0 -0
- package/dist/plugins/cannon/Cannon3DBodyComponent.d.ts +27 -0
- package/dist/plugins/cannon/Cannon3DShapeComponent.d.ts +57 -0
- package/dist/plugins/cannon/CannonPhysicsPlugin.d.ts +63 -0
- package/dist/plugins/cannon/CannonRagdollComponent.d.ts +148 -0
- package/dist/plugins/cannon/helper.d.ts +24 -0
- package/dist/plugins/cannon/threeToCannon.d.ts +63 -0
- package/dist/plugins/cannon/utils.d.ts +9 -0
- package/dist/projectFormat.js +108 -0
- package/dist/projectFormat.js.map +1 -0
- package/dist/runtime/createGame.d.ts +29 -0
- package/dist/runtime/index.d.ts +18 -0
- package/dist/runtime/migrations.d.ts +5 -0
- package/dist/runtime/nestedAssets.d.ts +26 -0
- package/dist/runtime/projectFormat.d.ts +83 -0
- package/dist/runtime/version.d.ts +1 -0
- package/dist/runtime.js +72835 -0
- package/dist/runtime.js.map +1 -0
- package/dist/sceneSerialization.d.ts +17 -0
- package/dist/sceneSerialization.js +174 -0
- package/dist/sceneSerialization.js.map +1 -0
- package/dist/scripts.d.ts +17 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/package.json +86 -0
- package/src/authoring.ts +293 -0
- package/src/authoringValidation.ts +815 -0
- package/src/defaults.ts +277 -0
- package/src/fileTypes.ts +53 -0
- package/src/importMap.ts +105 -0
- package/src/index.ts +15 -0
- package/src/paths.ts +9 -0
- package/src/plugins/GeneratorComponent.ts +275 -0
- package/src/plugins/HtmlUiComponent.example.ts +202 -0
- package/src/plugins/HtmlUiComponent.md +219 -0
- package/src/plugins/HtmlUiComponent.ts +320 -0
- package/src/plugins/cannon/Cannon3DBodyComponent.ts +227 -0
- package/src/plugins/cannon/Cannon3DShapeComponent.ts +258 -0
- package/src/plugins/cannon/CannonPhysicsPlugin.ts +409 -0
- package/src/plugins/cannon/CannonRagdollComponent.ts +1170 -0
- package/src/plugins/cannon/helper.ts +255 -0
- package/src/plugins/cannon/threeToCannon.ts +441 -0
- package/src/plugins/cannon/utils.ts +185 -0
- package/src/runtime/createGame.ts +337 -0
- package/src/runtime/index.ts +19 -0
- package/src/runtime/migrations.ts +6 -0
- package/src/runtime/nestedAssets.ts +226 -0
- package/src/runtime/projectFormat.ts +233 -0
- package/src/runtime/version.ts +3 -0
- package/src/sceneSerialization.ts +289 -0
- package/src/scripts.ts +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.js","sources":["../src/runtime/migrations.ts"],"sourcesContent":["export interface ProjectMigration {\n version: string\n migrate(projectRoot: string): void | Promise<void>\n}\n\nexport const PROJECT_MIGRATIONS: readonly ProjectMigration[] = []\n"],"names":["PROJECT_MIGRATIONS"],"mappings":"AAKO,MAAMA,IAAkD,CAAA;"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const KITE3D_DIRECTORY = ".kite3d";
|
|
2
|
+
export declare const DEPLOYS_PATH = ".kite3d/deploys.json";
|
|
3
|
+
export declare const JOURNAL_PATH = ".kite3d/journal.jsonl";
|
|
4
|
+
export declare const STATE_PATH = ".kite3d/state.json";
|
|
5
|
+
export declare const CONSOLE_PATH = ".kite3d/console.log";
|
|
6
|
+
export declare const THUMBS_DIRECTORY = ".kite3d/thumbs";
|
|
7
|
+
export declare const BACKUPS_DIRECTORY = ".kite3d/backups";
|
|
8
|
+
export declare const RUNNING_DIRECTORY = ".kite3d/running";
|
|
9
|
+
export declare const KITE3D_SERVER_CLIENT_ID = "kite3d-server";
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const o = ".kite3d", s = `${o}/deploys.json`, n = `${o}/journal.jsonl`, t = `${o}/state.json`, T = `${o}/console.log`, E = `${o}/thumbs`, R = `${o}/backups`, c = `${o}/running`, _ = "kite3d-server";
|
|
2
|
+
export {
|
|
3
|
+
R as BACKUPS_DIRECTORY,
|
|
4
|
+
T as CONSOLE_PATH,
|
|
5
|
+
s as DEPLOYS_PATH,
|
|
6
|
+
n as JOURNAL_PATH,
|
|
7
|
+
o as KITE3D_DIRECTORY,
|
|
8
|
+
_ as KITE3D_SERVER_CLIENT_ID,
|
|
9
|
+
c as RUNNING_DIRECTORY,
|
|
10
|
+
t as STATE_PATH,
|
|
11
|
+
E as THUMBS_DIRECTORY
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sources":["../src/paths.ts"],"sourcesContent":["export const KITE3D_DIRECTORY = '.kite3d'\nexport const DEPLOYS_PATH = `${KITE3D_DIRECTORY}/deploys.json`\nexport const JOURNAL_PATH = `${KITE3D_DIRECTORY}/journal.jsonl`\nexport const STATE_PATH = `${KITE3D_DIRECTORY}/state.json`\nexport const CONSOLE_PATH = `${KITE3D_DIRECTORY}/console.log`\nexport const THUMBS_DIRECTORY = `${KITE3D_DIRECTORY}/thumbs`\nexport const BACKUPS_DIRECTORY = `${KITE3D_DIRECTORY}/backups`\nexport const RUNNING_DIRECTORY = `${KITE3D_DIRECTORY}/running`\nexport const KITE3D_SERVER_CLIENT_ID = 'kite3d-server'\n"],"names":["KITE3D_DIRECTORY","DEPLOYS_PATH","JOURNAL_PATH","STATE_PATH","CONSOLE_PATH","THUMBS_DIRECTORY","BACKUPS_DIRECTORY","RUNNING_DIRECTORY","KITE3D_SERVER_CLIENT_ID"],"mappings":"AAAO,MAAMA,IAAmB,WACnBC,IAAe,GAAGD,CAAgB,iBAClCE,IAAe,GAAGF,CAAgB,kBAClCG,IAAa,GAAGH,CAAgB,eAChCI,IAAe,GAAGJ,CAAgB,gBAClCK,IAAmB,GAAGL,CAAgB,WACtCM,IAAoB,GAAGN,CAAgB,YACvCO,IAAoB,GAAGP,CAAgB,YACvCQ,IAA0B;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ComponentDefn, IObject3D, Object3DComponent, ThreeViewer } from 'threepipe';
|
|
2
|
+
export interface GeneratorParams {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface GeneratorContext {
|
|
6
|
+
node: IObject3D;
|
|
7
|
+
params: GeneratorParams;
|
|
8
|
+
viewer: ThreeViewer;
|
|
9
|
+
engine: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface GeneratorModule {
|
|
12
|
+
default?: (context: GeneratorContext) => unknown | Promise<unknown>;
|
|
13
|
+
}
|
|
14
|
+
export interface GeneratorViewerOptions {
|
|
15
|
+
base: string | URL;
|
|
16
|
+
onError?: (error: unknown) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class GeneratorComponent extends Object3DComponent {
|
|
19
|
+
static ComponentType: string;
|
|
20
|
+
static StateProperties: ComponentDefn['StateProperties'];
|
|
21
|
+
module: string;
|
|
22
|
+
params: GeneratorParams;
|
|
23
|
+
private runRevision;
|
|
24
|
+
static configureViewer(viewer: ThreeViewer, options: GeneratorViewerOptions): void;
|
|
25
|
+
static waitForViewer(viewer: ThreeViewer): Promise<void>;
|
|
26
|
+
init(object: IObject3D, state: Record<string, unknown>): void;
|
|
27
|
+
run(): Promise<void>;
|
|
28
|
+
bake(): Promise<number>;
|
|
29
|
+
destroy(): Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
export interface RunGeneratorOptions extends Omit<GeneratorContext, 'engine'> {
|
|
32
|
+
module: string;
|
|
33
|
+
base: URL;
|
|
34
|
+
revision?: number;
|
|
35
|
+
isCurrent?: () => boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare function runGenerator({ node, params, viewer, module, base, revision, isCurrent, }: RunGeneratorOptions): Promise<IObject3D[]>;
|
|
38
|
+
export declare function removeGeneratedChildren(node: IObject3D): void;
|
|
39
|
+
export declare function markGenerated(object: IObject3D, sourceId?: string, outputIndex?: number): void;
|
|
40
|
+
export declare function resolveGeneratorModule(module: string, base: URL): URL;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ComponentDefn, ComponentJSON, IObject3D, Object3DComponent, ViewerEventMap } from 'threepipe';
|
|
2
|
+
export declare const uiPositionMode: readonly ["world", "screen", "viewport"];
|
|
3
|
+
export type UiPositionMode = typeof uiPositionMode[number];
|
|
4
|
+
export declare class HtmlUiComponent extends Object3DComponent {
|
|
5
|
+
static ComponentType: string;
|
|
6
|
+
static StateProperties: ComponentDefn['StateProperties'];
|
|
7
|
+
element: HTMLDivElement;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
htmlData: string;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
scrollable: boolean;
|
|
13
|
+
interactable: boolean;
|
|
14
|
+
visible: boolean;
|
|
15
|
+
appendToBody: boolean;
|
|
16
|
+
positionMode: UiPositionMode;
|
|
17
|
+
offsetX: number;
|
|
18
|
+
offsetY: number;
|
|
19
|
+
zIndex: number;
|
|
20
|
+
private _worldPosition;
|
|
21
|
+
private _animationFrameId?;
|
|
22
|
+
constructor();
|
|
23
|
+
private _objectUpdate;
|
|
24
|
+
init(object: IObject3D, state: ComponentJSON['state']): void;
|
|
25
|
+
destroy(): Record<string, any>;
|
|
26
|
+
private _stopPositionTracking;
|
|
27
|
+
preFrame({ resized }: ViewerEventMap["preFrame"]): boolean | void;
|
|
28
|
+
private _updateElementPosition;
|
|
29
|
+
private _updateWorldPosition;
|
|
30
|
+
private _updateScreenPosition;
|
|
31
|
+
private _updateViewportPosition;
|
|
32
|
+
/**
|
|
33
|
+
* Update the HTML content programmatically
|
|
34
|
+
*/
|
|
35
|
+
setHtml(html: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Set the position
|
|
38
|
+
*/
|
|
39
|
+
setPosition(x: number, y: number): void;
|
|
40
|
+
/**
|
|
41
|
+
* Set the size
|
|
42
|
+
*/
|
|
43
|
+
setSize(width: number, height: number): void;
|
|
44
|
+
/**
|
|
45
|
+
* Show the element
|
|
46
|
+
*/
|
|
47
|
+
show(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Hide the element
|
|
50
|
+
*/
|
|
51
|
+
hide(): void;
|
|
52
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Body } from 'cannon-es';
|
|
2
|
+
import { ComponentDefn, ComponentJSON, IObject3D, Object3DComponent } from 'threepipe';
|
|
3
|
+
import { Cannon3DShapeComponent } from './Cannon3DShapeComponent.ts';
|
|
4
|
+
import { CannonMaterial2 } from './CannonPhysicsPlugin.ts';
|
|
5
|
+
export declare const physicsBodyType: readonly ["static", "dynamic", "kinematic"];
|
|
6
|
+
export type PhysicsBodyType = typeof physicsBodyType[number];
|
|
7
|
+
export declare class Cannon3DBodyComponent extends Object3DComponent {
|
|
8
|
+
static ComponentType: string;
|
|
9
|
+
static StateProperties: ComponentDefn['StateProperties'];
|
|
10
|
+
body: Body;
|
|
11
|
+
mass: number;
|
|
12
|
+
type: PhysicsBodyType;
|
|
13
|
+
isTrigger: boolean;
|
|
14
|
+
material: CannonMaterial2;
|
|
15
|
+
private _typeToCannon;
|
|
16
|
+
updateMassProperties(): void;
|
|
17
|
+
updateBoundingRadius(): void;
|
|
18
|
+
constructor();
|
|
19
|
+
private _objectUpdate;
|
|
20
|
+
init(object: IObject3D, state: ComponentJSON['state']): void;
|
|
21
|
+
destroy(): Record<string, any>;
|
|
22
|
+
resetTransform(changeKey?: string): void;
|
|
23
|
+
shapeRefs: Cannon3DShapeComponent[];
|
|
24
|
+
addShape(shape: Cannon3DShapeComponent, refresh?: boolean): void;
|
|
25
|
+
removeShape(shape: Cannon3DShapeComponent, refresh?: boolean): void;
|
|
26
|
+
refreshShapes(update?: boolean): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AHelperWidget, ComponentDefn, ComponentJSON, IObject3D, Object3DComponent, PartialRecord } from 'threepipe';
|
|
2
|
+
import { ShapeParameters, ShapeResult, ShapeType } from './threeToCannon';
|
|
3
|
+
import { Cannon3DBodyComponent } from './Cannon3DBodyComponent.ts';
|
|
4
|
+
export declare const typeToCannon: {
|
|
5
|
+
readonly autoBox: ShapeType.BOX;
|
|
6
|
+
readonly autoCylinder: ShapeType.CYLINDER;
|
|
7
|
+
readonly autoSphere: ShapeType.SPHERE;
|
|
8
|
+
readonly autoConvex: ShapeType.HULL;
|
|
9
|
+
readonly autoTrimesh: ShapeType.MESH;
|
|
10
|
+
readonly box: ShapeType.BOX;
|
|
11
|
+
readonly sphere: ShapeType.SPHERE;
|
|
12
|
+
readonly cylinder: ShapeType.CYLINDER;
|
|
13
|
+
readonly convex: ShapeType.HULL;
|
|
14
|
+
readonly trimesh: ShapeType.MESH;
|
|
15
|
+
};
|
|
16
|
+
export type CannonShapeType = keyof typeof typeToCannon;
|
|
17
|
+
export declare const cannonShapeTypes: CannonShapeType[];
|
|
18
|
+
export declare const cannonShapeTypeParams: PartialRecord<CannonShapeType, ShapeParameters['params']>;
|
|
19
|
+
export declare class Cannon3DShapeComponent extends Object3DComponent {
|
|
20
|
+
static ComponentType: string;
|
|
21
|
+
static StateProperties: ComponentDefn['StateProperties'];
|
|
22
|
+
static EmptyResult: ShapeResult;
|
|
23
|
+
result: ShapeResult;
|
|
24
|
+
bodyRef: Cannon3DBodyComponent | undefined;
|
|
25
|
+
type: CannonShapeType;
|
|
26
|
+
params: ShapeParameters | null;
|
|
27
|
+
constructor();
|
|
28
|
+
init(object: IObject3D, state: ComponentJSON['state']): void;
|
|
29
|
+
destroy(): Record<string, any>;
|
|
30
|
+
refreshShape(refreshBody?: boolean): void;
|
|
31
|
+
private _needsUpdate;
|
|
32
|
+
objectUpdate: (e: any) => void;
|
|
33
|
+
childadded: (e: any) => void;
|
|
34
|
+
childremoved: (e: any) => void;
|
|
35
|
+
preFrame: () => void;
|
|
36
|
+
}
|
|
37
|
+
export declare class Cannon3DShapeHelper extends AHelperWidget {
|
|
38
|
+
autoUpgradeChildren: boolean;
|
|
39
|
+
private _shapes;
|
|
40
|
+
private _meshes;
|
|
41
|
+
object: IObject3D | undefined;
|
|
42
|
+
private _gp;
|
|
43
|
+
constructor(object: IObject3D);
|
|
44
|
+
update(): void;
|
|
45
|
+
dispose(): void;
|
|
46
|
+
static Check(obj: IObject3D): boolean;
|
|
47
|
+
static Create(obj: IObject3D): Cannon3DShapeHelper;
|
|
48
|
+
}
|
|
49
|
+
declare module 'threepipe' {
|
|
50
|
+
interface IObject3D {
|
|
51
|
+
/**
|
|
52
|
+
* Shapes associated with this object
|
|
53
|
+
* @internal - for cannon js physics
|
|
54
|
+
*/
|
|
55
|
+
['__cannonShapes']?: ShapeResult[];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Body, ContactMaterial, Material as CannonMaterial, Shape, World } from 'cannon-es';
|
|
2
|
+
import { AViewerPluginSync, EntityComponentPlugin, IObject3D, IViewerEvent, ThreeViewer } from 'threepipe';
|
|
3
|
+
import { Cannon3DShapeComponent } from './Cannon3DShapeComponent.ts';
|
|
4
|
+
import { Cannon3DBodyComponent } from './Cannon3DBodyComponent.ts';
|
|
5
|
+
import { CannonRagdollComponent } from './CannonRagdollComponent.ts';
|
|
6
|
+
export declare class CannonMaterial2 extends CannonMaterial {
|
|
7
|
+
name: string;
|
|
8
|
+
uuid: string;
|
|
9
|
+
friction: number;
|
|
10
|
+
restitution: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class CannonPhysicsPlugin extends AViewerPluginSync {
|
|
13
|
+
static readonly PluginType = "CannonPhysicsPlugin";
|
|
14
|
+
private _world;
|
|
15
|
+
get world(): World;
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
static CannonTypes: {
|
|
18
|
+
Body: typeof Body;
|
|
19
|
+
Shape: typeof Shape;
|
|
20
|
+
World: typeof World;
|
|
21
|
+
Material: typeof CannonMaterial;
|
|
22
|
+
ContactMaterial: typeof ContactMaterial;
|
|
23
|
+
};
|
|
24
|
+
running: boolean;
|
|
25
|
+
nextSteps: number;
|
|
26
|
+
stepPhysics: any;
|
|
27
|
+
defaultMaterial: CannonMaterial2;
|
|
28
|
+
constructor(enabled?: boolean, running?: boolean);
|
|
29
|
+
dependencies: (typeof EntityComponentPlugin)[];
|
|
30
|
+
private _v1;
|
|
31
|
+
private _v2;
|
|
32
|
+
private _s2;
|
|
33
|
+
private _q1;
|
|
34
|
+
private _q2;
|
|
35
|
+
private _m1;
|
|
36
|
+
private _m2;
|
|
37
|
+
frameFadeToggled: boolean;
|
|
38
|
+
protected _preFrame: (e: IViewerEvent) => void;
|
|
39
|
+
private _onRemove;
|
|
40
|
+
onAdded(viewer: ThreeViewer): Promise<void>;
|
|
41
|
+
private _objectAdd;
|
|
42
|
+
private _objectRemove;
|
|
43
|
+
onRemove(viewer: ThreeViewer): void;
|
|
44
|
+
readonly componentTypes: {
|
|
45
|
+
body: typeof Cannon3DBodyComponent;
|
|
46
|
+
shape: typeof Cannon3DShapeComponent;
|
|
47
|
+
ragdoll: typeof CannonRagdollComponent;
|
|
48
|
+
};
|
|
49
|
+
bodyComponents: Set<Cannon3DBodyComponent>;
|
|
50
|
+
cannonBodies: WeakMap<Body, Cannon3DBodyComponent>;
|
|
51
|
+
addBody(body: Cannon3DBodyComponent): void;
|
|
52
|
+
removeBody(body: Cannon3DBodyComponent): void;
|
|
53
|
+
}
|
|
54
|
+
export interface CollisionEvent {
|
|
55
|
+
object: IObject3D;
|
|
56
|
+
body: Cannon3DBodyComponent;
|
|
57
|
+
}
|
|
58
|
+
declare module 'threepipe' {
|
|
59
|
+
interface Object3DComponent {
|
|
60
|
+
onBeginContact?(collisionEvent: any): void;
|
|
61
|
+
onEndContact?(collisionEvent: any): void;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Body, ConeTwistConstraint, Constraint, Vec3 } from 'cannon-es';
|
|
2
|
+
import { ComponentDefn, ComponentJSON, IObject3D, Object3DComponent, ViewerEventMap } from 'threepipe';
|
|
3
|
+
import { CannonMaterial2 } from './CannonPhysicsPlugin.ts';
|
|
4
|
+
export interface RagdollConfig {
|
|
5
|
+
scale: number;
|
|
6
|
+
angle: number;
|
|
7
|
+
angleShoulders: number;
|
|
8
|
+
twistAngle: number;
|
|
9
|
+
}
|
|
10
|
+
export interface RagdollParts {
|
|
11
|
+
lowerLeftLeg: Body;
|
|
12
|
+
lowerRightLeg: Body;
|
|
13
|
+
upperLeftLeg: Body;
|
|
14
|
+
upperRightLeg: Body;
|
|
15
|
+
pelvis: Body;
|
|
16
|
+
upperBody: Body;
|
|
17
|
+
head: Body;
|
|
18
|
+
upperLeftArm: Body;
|
|
19
|
+
upperRightArm: Body;
|
|
20
|
+
lowerLeftArm: Body;
|
|
21
|
+
lowerRightArm: Body;
|
|
22
|
+
}
|
|
23
|
+
export interface RagdollConstraints {
|
|
24
|
+
neckJoint: ConeTwistConstraint;
|
|
25
|
+
leftKneeJoint: ConeTwistConstraint;
|
|
26
|
+
rightKneeJoint: ConeTwistConstraint;
|
|
27
|
+
leftHipJoint: ConeTwistConstraint;
|
|
28
|
+
rightHipJoint: ConeTwistConstraint;
|
|
29
|
+
spineJoint: ConeTwistConstraint;
|
|
30
|
+
leftShoulder: ConeTwistConstraint;
|
|
31
|
+
rightShoulder: ConeTwistConstraint;
|
|
32
|
+
leftElbowJoint: ConeTwistConstraint;
|
|
33
|
+
rightElbowJoint: ConeTwistConstraint;
|
|
34
|
+
}
|
|
35
|
+
export declare class CannonRagdollComponent extends Object3DComponent {
|
|
36
|
+
static ComponentType: string;
|
|
37
|
+
static StateProperties: ComponentDefn['StateProperties'];
|
|
38
|
+
scale: number;
|
|
39
|
+
angle: number;
|
|
40
|
+
angleShoulders: number;
|
|
41
|
+
twistAngle: number;
|
|
42
|
+
mass: number;
|
|
43
|
+
/** If true, creates ragdoll bodies on init. If false, waits for activate() call */
|
|
44
|
+
autoCreateOnInit: boolean;
|
|
45
|
+
/** If true, hides the debug ragdoll meshes (useful when using with character model) */
|
|
46
|
+
hideRagdollMeshes: boolean;
|
|
47
|
+
material: CannonMaterial2;
|
|
48
|
+
private _bodies;
|
|
49
|
+
private _constraints;
|
|
50
|
+
private _parts;
|
|
51
|
+
private _ragdollConstraints;
|
|
52
|
+
private _cannon;
|
|
53
|
+
private _meshes;
|
|
54
|
+
private _meshContainer;
|
|
55
|
+
private _visualMaterial;
|
|
56
|
+
private _lastObjectPosition;
|
|
57
|
+
private _lastObjectQuaternion;
|
|
58
|
+
private _initialized;
|
|
59
|
+
private _isActive;
|
|
60
|
+
private _characterMeshes;
|
|
61
|
+
private _boneMap;
|
|
62
|
+
private _initialBoneQuats;
|
|
63
|
+
private _initialBoneWorldQuats;
|
|
64
|
+
private _initialBodyQuats;
|
|
65
|
+
private _boneNames;
|
|
66
|
+
private _currentObjectPosition;
|
|
67
|
+
private _currentObjectQuaternion;
|
|
68
|
+
private _deltaQuaternion;
|
|
69
|
+
private _invLastQuaternion;
|
|
70
|
+
private _tempVec3;
|
|
71
|
+
private _pivotPoint;
|
|
72
|
+
private _tempWorldPos;
|
|
73
|
+
private _tempWorldQuat;
|
|
74
|
+
get bodies(): Body[];
|
|
75
|
+
get constraints(): Constraint[];
|
|
76
|
+
get parts(): RagdollParts | null;
|
|
77
|
+
get ragdollConstraints(): RagdollConstraints | null;
|
|
78
|
+
/** Returns true if ragdoll physics is currently active */
|
|
79
|
+
get isActive(): boolean;
|
|
80
|
+
constructor();
|
|
81
|
+
init(object: IObject3D, state: ComponentJSON['state']): void;
|
|
82
|
+
destroy(): Record<string, any>;
|
|
83
|
+
preFrame(_event: ViewerEventMap["preFrame"]): void;
|
|
84
|
+
/**
|
|
85
|
+
* Syncs the character's bones to match the ragdoll body positions/rotations.
|
|
86
|
+
* Called each frame when ragdoll is active.
|
|
87
|
+
*
|
|
88
|
+
* The approach:
|
|
89
|
+
* 1. Calculate how much the ragdoll body has rotated in world space (delta from initial)
|
|
90
|
+
* 2. Apply that same world-space delta to the bone's initial world orientation
|
|
91
|
+
* 3. Convert the new world orientation back to local space for the bone
|
|
92
|
+
*
|
|
93
|
+
* Note: Only the root bone (hips) gets position updates. Other bones only get rotation updates
|
|
94
|
+
* because in a skeleton hierarchy, bone positions are fixed (defined by bone length).
|
|
95
|
+
*/
|
|
96
|
+
private _syncRagdollToBones;
|
|
97
|
+
private _syncObjectPosition;
|
|
98
|
+
private _updateMeshes;
|
|
99
|
+
private _recreateRagdoll;
|
|
100
|
+
private _updateMass;
|
|
101
|
+
private _updateConstraints;
|
|
102
|
+
private _createRagdoll;
|
|
103
|
+
private _removeRagdoll;
|
|
104
|
+
/**
|
|
105
|
+
* Reset the ragdoll to its initial position relative to the object
|
|
106
|
+
*/
|
|
107
|
+
resetPosition(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Apply an impulse to all bodies
|
|
110
|
+
*/
|
|
111
|
+
applyImpulse(impulse: Vec3, worldPoint?: Vec3): void;
|
|
112
|
+
/**
|
|
113
|
+
* Apply an impulse to a specific body part
|
|
114
|
+
*/
|
|
115
|
+
applyImpulseToPart(partName: keyof RagdollParts, impulse: Vec3, worldPoint?: Vec3): void;
|
|
116
|
+
private _updateMeshVisibility;
|
|
117
|
+
private _findCharacterMeshes;
|
|
118
|
+
private _buildBoneMap;
|
|
119
|
+
private _findBone;
|
|
120
|
+
private _getBoneWorldPosition;
|
|
121
|
+
private _getBoneWorldQuaternion;
|
|
122
|
+
start(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Activates the ragdoll physics simulation.
|
|
125
|
+
* Call this when the character should start ragdolling (e.g., on death).
|
|
126
|
+
* @param impulse Optional initial impulse to apply (e.g., from bullet impact)
|
|
127
|
+
* @param impactPoint Optional world point where impulse is applied
|
|
128
|
+
*/
|
|
129
|
+
activate(impulse?: Vec3, impactPoint?: Vec3): void;
|
|
130
|
+
/**
|
|
131
|
+
* Store initial bone quaternions (both local and world space) for rotation offset calculation
|
|
132
|
+
*/
|
|
133
|
+
private _storeInitialBoneQuats;
|
|
134
|
+
/**
|
|
135
|
+
* Store initial body quaternions (world space) for rotation offset calculation
|
|
136
|
+
*/
|
|
137
|
+
private _storeInitialBodyQuats;
|
|
138
|
+
/**
|
|
139
|
+
* Deactivates the ragdoll and restores the character.
|
|
140
|
+
* Call this to reset the character to normal state.
|
|
141
|
+
*/
|
|
142
|
+
deactivate(): void;
|
|
143
|
+
private _matchBonesToRagdoll;
|
|
144
|
+
private _activateBodies;
|
|
145
|
+
private _deactivateBodies;
|
|
146
|
+
private _setCharacterVisible;
|
|
147
|
+
private _findClosestBody;
|
|
148
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ConvexPolyhedron, Heightfield, Shape, Trimesh } from 'cannon-es';
|
|
2
|
+
import { BufferGeometry, Mesh } from 'threepipe';
|
|
3
|
+
type ComplexShape = Shape & {
|
|
4
|
+
geometryId?: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function cannonDebugger(): {
|
|
7
|
+
createConvexPolyhedronGeometry: (shape: ConvexPolyhedron) => BufferGeometry;
|
|
8
|
+
createTrimeshGeometry: (shape: Trimesh) => BufferGeometry;
|
|
9
|
+
createHeightfieldGeometry: (shape: Heightfield) => BufferGeometry;
|
|
10
|
+
createMesh: (shape: Shape) => Mesh;
|
|
11
|
+
scaleMesh: (mesh: Mesh, shape: Shape | ComplexShape) => void;
|
|
12
|
+
typeMatch: (mesh: Mesh | undefined, shape: Shape | ComplexShape) => boolean;
|
|
13
|
+
updateMesh: (mesh: Mesh | undefined, shape: Shape | ComplexShape) => Mesh<BufferGeometry<import('three').NormalBufferAttributes, import('three').BufferGeometryEventMap>, import('three').Material<import('three').MaterialEventMap> | import('three').Material<import('three').MaterialEventMap>[], import('three').Object3DEventMap> | undefined;
|
|
14
|
+
};
|
|
15
|
+
export declare const CannonDebugger: {
|
|
16
|
+
createConvexPolyhedronGeometry: (shape: ConvexPolyhedron) => BufferGeometry;
|
|
17
|
+
createTrimeshGeometry: (shape: Trimesh) => BufferGeometry;
|
|
18
|
+
createHeightfieldGeometry: (shape: Heightfield) => BufferGeometry;
|
|
19
|
+
createMesh: (shape: Shape) => Mesh;
|
|
20
|
+
scaleMesh: (mesh: Mesh, shape: Shape | ComplexShape) => void;
|
|
21
|
+
typeMatch: (mesh: Mesh | undefined, shape: Shape | ComplexShape) => boolean;
|
|
22
|
+
updateMesh: (mesh: Mesh | undefined, shape: Shape | ComplexShape) => Mesh<BufferGeometry<import('three').NormalBufferAttributes, import('three').BufferGeometryEventMap>, import('three').Material<import('three').MaterialEventMap> | import('three').Material<import('three').MaterialEventMap>[], import('three').Object3DEventMap> | undefined;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Quaternion as CQuaternion, Shape, Vec3 } from 'cannon-es';
|
|
2
|
+
import { Object3D } from 'threepipe';
|
|
3
|
+
export type BoxParameters = {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
z: number;
|
|
7
|
+
};
|
|
8
|
+
export type CylinderParameters = {
|
|
9
|
+
radiusTop: number;
|
|
10
|
+
radiusBottom: number;
|
|
11
|
+
height: number;
|
|
12
|
+
segments: number;
|
|
13
|
+
};
|
|
14
|
+
export type SphereParameters = {
|
|
15
|
+
radius: number;
|
|
16
|
+
};
|
|
17
|
+
export type ConvexPolyhedronParameters = {
|
|
18
|
+
vertices: Float32Array;
|
|
19
|
+
faces: number[][];
|
|
20
|
+
};
|
|
21
|
+
export type TrimeshParameters = {
|
|
22
|
+
vertices: Float32Array;
|
|
23
|
+
indices: Uint32Array;
|
|
24
|
+
};
|
|
25
|
+
type ShapeTypeToShapeParameters = {
|
|
26
|
+
Box: BoxParameters;
|
|
27
|
+
Cylinder: CylinderParameters;
|
|
28
|
+
Sphere: SphereParameters;
|
|
29
|
+
ConvexPolyhedron: ConvexPolyhedronParameters;
|
|
30
|
+
Trimesh: TrimeshParameters;
|
|
31
|
+
};
|
|
32
|
+
export declare enum ShapeType {
|
|
33
|
+
BOX = "Box",
|
|
34
|
+
CYLINDER = "Cylinder",
|
|
35
|
+
SPHERE = "Sphere",
|
|
36
|
+
HULL = "ConvexPolyhedron",
|
|
37
|
+
MESH = "Trimesh"
|
|
38
|
+
}
|
|
39
|
+
export interface ShapeOptions {
|
|
40
|
+
type?: ShapeType;
|
|
41
|
+
cylinderAxis?: 'x' | 'y' | 'z';
|
|
42
|
+
sphereRadius?: number;
|
|
43
|
+
}
|
|
44
|
+
export interface ShapeParameters<T extends ShapeType = ShapeType> {
|
|
45
|
+
type: T;
|
|
46
|
+
params: ShapeTypeToShapeParameters[T];
|
|
47
|
+
offset?: Vec3;
|
|
48
|
+
orientation?: CQuaternion;
|
|
49
|
+
}
|
|
50
|
+
export interface ShapeResult<T extends Shape = Shape> {
|
|
51
|
+
shape: T;
|
|
52
|
+
offset?: Vec3;
|
|
53
|
+
orientation?: CQuaternion;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Given a THREE.Object3D instance, creates parameters for a CANNON shape.
|
|
57
|
+
*/
|
|
58
|
+
export declare const getShapeParameters: (object: Object3D, options?: ShapeOptions) => ShapeParameters | null;
|
|
59
|
+
/**
|
|
60
|
+
* Given a THREE.Object3D instance, creates a corresponding CANNON shape.
|
|
61
|
+
*/
|
|
62
|
+
export declare const threeToCannon: (object: Object3D, options?: ShapeOptions, shapeParameters?: ShapeParameters | null) => ShapeResult | null;
|
|
63
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BufferGeometry, Object3D, Vector3 } from 'threepipe';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a single geometry for the given object. If the object is compound,
|
|
4
|
+
* its geometries are automatically merged. Bake world scale into each
|
|
5
|
+
* geometry, because we can't easily apply that to the cannonjs shapes later.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getGeometry(object: Object3D): BufferGeometry | null;
|
|
8
|
+
export declare function getVertices(geometry: BufferGeometry): Float32Array;
|
|
9
|
+
export declare function getComponent(v: Vector3, component: string): number;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { parse as w } from "jsonc-parser";
|
|
2
|
+
const b = "kite3d", S = `/${b}/`;
|
|
3
|
+
function v(t, e) {
|
|
4
|
+
const n = e.dependencies;
|
|
5
|
+
return g(n) && Object.prototype.hasOwnProperty.call(n, t);
|
|
6
|
+
}
|
|
7
|
+
function O(t) {
|
|
8
|
+
const e = w(t);
|
|
9
|
+
if (!e || typeof e != "object" || Array.isArray(e))
|
|
10
|
+
throw new Error("Invalid package.json file: expected an object");
|
|
11
|
+
const n = e;
|
|
12
|
+
if (typeof n.mainScene != "string" || !n.mainScene.toLowerCase().endsWith(".gltf"))
|
|
13
|
+
throw new Error("package.json mainScene must name a text .gltf file");
|
|
14
|
+
return n;
|
|
15
|
+
}
|
|
16
|
+
function x(t) {
|
|
17
|
+
const e = w(t);
|
|
18
|
+
if (e.files && typeof e.files != "object")
|
|
19
|
+
throw new Error("Invalid assets.json file: files should be an object");
|
|
20
|
+
if (e.version !== void 0 && typeof e.version != "number")
|
|
21
|
+
throw new Error("Invalid assets.json file: version should be a number");
|
|
22
|
+
return e.files || (e.files = {}), e.version || (e.version = 1), e;
|
|
23
|
+
}
|
|
24
|
+
function N(t, e) {
|
|
25
|
+
const n = JSON.parse(e);
|
|
26
|
+
if (!n || typeof n != "object" || !n.asset)
|
|
27
|
+
throw new Error(`${t} is not a JSON glTF document`);
|
|
28
|
+
}
|
|
29
|
+
function k(t) {
|
|
30
|
+
var e;
|
|
31
|
+
try {
|
|
32
|
+
const n = JSON.parse(t), i = [];
|
|
33
|
+
for (const [c, a] of (n.nodes || []).entries())
|
|
34
|
+
for (const [p, o] of Object.entries(((e = a.extras) == null ? void 0 : e.EntityComponentPlugin) || {}))
|
|
35
|
+
o.type !== "Generator" || !g(o.state) || i.push({
|
|
36
|
+
componentId: p,
|
|
37
|
+
module: typeof o.state.module == "string" ? o.state.module : "",
|
|
38
|
+
nodeIndex: c,
|
|
39
|
+
nodeName: typeof a.name == "string" ? a.name : `Node ${c}`,
|
|
40
|
+
params: g(o.state.params) ? o.state.params : {}
|
|
41
|
+
});
|
|
42
|
+
return i;
|
|
43
|
+
} catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function A(t, e, n) {
|
|
48
|
+
var a, p, o, f, d;
|
|
49
|
+
const i = JSON.parse(t), c = (d = (f = (o = (p = (a = i.nodes) == null ? void 0 : a[e.nodeIndex]) == null ? void 0 : p.extras) == null ? void 0 : o.EntityComponentPlugin) == null ? void 0 : f[e.componentId]) == null ? void 0 : d.state;
|
|
50
|
+
if (!g(c)) throw new Error(`Generator component is missing on ${e.nodeName}`);
|
|
51
|
+
return Object.assign(c, n), { text: JSON.stringify(i, null, 2), state: c };
|
|
52
|
+
}
|
|
53
|
+
async function E(t, e) {
|
|
54
|
+
var f, d;
|
|
55
|
+
const n = t[b] ?? {}, i = [], a = {
|
|
56
|
+
...t.dependencies && typeof t.dependencies == "object" && !Array.isArray(t.dependencies) ? t.dependencies : {}
|
|
57
|
+
};
|
|
58
|
+
i.push(...Object.entries(a).map(([s, r]) => ({ key: s, version: r }))), n.imports && i.push(...Object.entries(n.imports).map(([s, r]) => ({
|
|
59
|
+
key: s,
|
|
60
|
+
url: r.startsWith("@") ? void 0 : r,
|
|
61
|
+
version: r.startsWith("@") ? r.slice(1) : ""
|
|
62
|
+
})));
|
|
63
|
+
const p = ((f = n.plugins) == null ? void 0 : f.map((s) => {
|
|
64
|
+
if (typeof s != "string") return s;
|
|
65
|
+
const r = s.match(/\((.*)\)$/);
|
|
66
|
+
let y, l = s;
|
|
67
|
+
if (r) {
|
|
68
|
+
const h = r[1].trim();
|
|
69
|
+
if (l = s.slice(0, r.index).trim(), h)
|
|
70
|
+
try {
|
|
71
|
+
const m = [];
|
|
72
|
+
if (y = w(`[${h}]`, m), !Array.isArray(y) || m.length)
|
|
73
|
+
throw console.error(m), new Error("Plugin params is not a valid array");
|
|
74
|
+
} catch (m) {
|
|
75
|
+
return console.error("Unable to parse plugin params, skipping plugin", s, h, m), null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const u = l.lastIndexOf(":");
|
|
79
|
+
return {
|
|
80
|
+
import: u !== -1 ? l.slice(0, u) : l,
|
|
81
|
+
className: u !== -1 ? l.slice(u + 1) : void 0,
|
|
82
|
+
params: y
|
|
83
|
+
};
|
|
84
|
+
})) || [], o = ((d = n.scripts) == null ? void 0 : d.map(
|
|
85
|
+
(s) => typeof s == "string" ? { import: s } : s
|
|
86
|
+
)) || [];
|
|
87
|
+
return {
|
|
88
|
+
plugins: p.filter(Boolean),
|
|
89
|
+
scripts: o,
|
|
90
|
+
dependencies: i,
|
|
91
|
+
viewer: n.viewer || {}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function g(t) {
|
|
95
|
+
return !!t && typeof t == "object" && !Array.isArray(t);
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
S as assetUrlPrefix,
|
|
99
|
+
v as isDependencyModuleSpecifier,
|
|
100
|
+
x as parseAssetsJSONManifest,
|
|
101
|
+
O as parsePackageJSON,
|
|
102
|
+
E as parsePackageJsonSettingsConfig,
|
|
103
|
+
k as readProjectGeneratorStates,
|
|
104
|
+
b as settingsKey,
|
|
105
|
+
A as updateProjectGeneratorState,
|
|
106
|
+
N as validateSceneSource
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=projectFormat.js.map
|