@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
101 lines (100 loc) • 4.05 kB
TypeScript
import { Object3D } from "three";
import { type IInstantiateOptions } from "./engine_gameobject.js";
import type { INetworkConnection } from "./engine_networking_types.js";
import type { IModel } from "./engine_networking_types.js";
import { Context } from "./engine_setup.js";
import type { IComponent as Component, IGameObject as GameObject } from "./engine_types.js";
import type { UIDProvider } from "./engine_types.js";
export declare class InstantiateIdProvider implements UIDProvider {
get seed(): number;
set seed(val: number);
private _originalSeed;
private _seed;
constructor(seed: string | number);
reset(): void;
generateUUID(str?: string): string;
initialize(strOrNumber: string | number): void;
static createFromString(str: string): InstantiateIdProvider;
private static hash;
}
export declare enum InstantiateEvent {
NewInstanceCreated = "new-instance-created",
InstanceDestroyed = "instance-destroyed"
}
export interface IBeforeNetworkedDestroy {
onBeforeNetworkedDestroy(networkIds: string[]): void;
}
declare type SyncDestroyOptions = {
/** When true the state will be saved in the networking backend */
saveInRoom?: boolean;
};
/**
* Destroy an object across the network. See also {@link syncInstantiate}.
* @param obj The object or component to be destroyed
* @param con The network connection to send the destroy event to
* @param recursive If true, all children will be destroyed as well. Default is true
* @param opts Options for the destroy operation
* @category Networking
*/
export declare function syncDestroy(obj: GameObject | Component, con: INetworkConnection, recursive?: boolean, opts?: SyncDestroyOptions): void;
export declare function sendDestroyed(guid: string, con: INetworkConnection, opts?: SyncDestroyOptions): void;
export declare function beginListenDestroy(context: Context): void;
/**
* When a file is instantiated via some server (e.g. via file drop) we also want to send the info where the file can be downloaded.
* @internal
*/
export declare class HostData {
/** File to download */
filename: string;
/** Checksum to verify its the correct file */
hash: string;
/** Expected size of the referenced file and its dependencies */
size: number;
constructor(filename: string, hash: string, size: number);
}
export declare class NewInstanceModel implements IModel {
guid: string;
originalGuid: string;
seed: number | undefined;
visible: boolean | undefined;
hostData: HostData | undefined;
dontSave?: boolean | undefined;
parent: string | undefined;
position: {
x: number;
y: number;
z: number;
} | undefined;
rotation: {
x: number;
y: number;
z: number;
w: number;
} | undefined;
scale: {
x: number;
y: number;
z: number;
} | undefined;
/** Set to true to prevent this model from being instantiated */
preventCreation?: boolean;
/**
* When set this will delete the server state when the user disconnects
*/
deleteStateOnDisconnect?: boolean | undefined;
constructor(originalGuid: string, newGuid: string);
}
/**
* Instantiation options for {@link syncInstantiate}
*/
export type SyncInstantiateOptions = IInstantiateOptions & Pick<IModel, "deleteOnDisconnect">;
/**
* Instantiate an object across the network. See also {@link syncDestroy}.
* @category Networking
*/
export declare function syncInstantiate(object: GameObject | Object3D, opts: SyncInstantiateOptions, hostData?: HostData, save?: boolean): GameObject | null;
export declare function generateSeed(): number;
export declare function beginListenInstantiate(context: Context): void;
export declare type PrefabProviderCallback = (guid: string) => Promise<Object3D | null>;
export declare function registerPrefabProvider(key: string, fn: PrefabProviderCallback): void;
export {};