@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.
95 lines (94 loc) • 3.63 kB
TypeScript
import { Behaviour } from "./Component.js";
export declare const SyncedTransformIdentifier = "STRS";
/**
* Creates a flatbuffer model containing the transform data of a game object. Used by {@link SyncedTransform}
* @param guid The unique identifier of the object to sync
* @param b The behavior component containing transform data
* @param fast Whether to use fast mode synchronization (syncs more frequently)
* @returns A Uint8Array containing the serialized transform data
*/
export declare function createTransformModel(guid: string, b: Behaviour, fast?: boolean): Uint8Array;
/**
* SyncedTransform synchronizes the position and rotation of a game object over the network.
* It handles ownership transfer, interpolation, and network state updates automatically.
* @category Networking
* @group Components
*/
export declare class SyncedTransform extends Behaviour {
/** When true, overrides physics behavior when this object is owned by the local user */
overridePhysics: boolean;
/** Whether to smoothly interpolate position changes when receiving updates */
interpolatePosition: boolean;
/** Whether to smoothly interpolate rotation changes when receiving updates */
interpolateRotation: boolean;
/** When true, sends updates at a higher frequency, useful for fast-moving objects */
fastMode: boolean;
/** When true, notifies other clients when this object is destroyed */
syncDestroy: boolean;
private _model;
private _needsUpdate;
private rb;
private _wasKinematic;
private _receivedDataBefore;
private _targetPosition;
private _targetRotation;
private _receivedFastUpdate;
private _shouldRequestOwnership;
/**
* Requests ownership of this object on the network.
* You need to be connected to a room for this to work.
*/
requestOwnership(): void;
/**
* Free ownership of this object on the network.
* You need to be connected to a room for this to work.
* This will also be called automatically when the component is disabled.
*/
freeOwnership(): void;
/**
* Checks if this client has ownership of the object
* @returns true if this client has ownership, false if not, undefined if ownership state is unknown
*/
hasOwnership(): boolean | undefined;
/**
* Checks if the object is owned by any client
* @returns true if the object is owned, false if not, undefined if ownership state is unknown
*/
isOwned(): boolean | undefined;
private joinedRoomCallback;
private receivedDataCallback;
/** @internal */
awake(): void;
/** @internal */
onDestroy(): void;
/**
* Attempts to retrieve and apply the last known network state for this transform
*/
private tryGetLastState;
private tempEuler;
/**
* Handles incoming network data for this transform
* @param data The model containing transform information
*/
private onReceivedData;
/**
* @internal
* Initializes tracking of position and rotation when component is enabled
*/
onEnable(): void;
/**
* @internal
* Releases ownership when component is disabled
*/
onDisable(): void;
private receivedUpdate;
private lastPosition;
private lastRotation;
private lastScale;
/**
* @internal
* Handles transform synchronization before each render frame
* Sends updates when owner, receives and applies updates when not owner
*/
onBeforeRender(): void;
}