@playcanvas/react
Version:
A React renderer for PlayCanvas – build interactive 3D applications using React's declarative paradigm.
87 lines (86 loc) • 2.84 kB
TypeScript
import { Entity as PcEntity } from 'playcanvas';
import { ReactNode } from 'react';
import { SyntheticMouseEvent, SyntheticPointerEvent } from './utils/synthetic-event';
import { PublicProps } from './utils/types-utils';
/**
* The Entity component is the fundamental building block of a PlayCanvas scene.
* It represents a node in the scene graph and can have components attached to it.
*
* @example
* // Basic usage
* <Entity name="myEntity" position={[0, 1, 0]}>
* <Render type="box" />
* </Entity>
*
* @example
* // With pointer events
* <Entity
* position={[0, 1, 0]}
* onPointerDown={(e) => console.log('Clicked!')}
* onClick={(e) => console.log('Mouse clicked!')}
* >
* <Render type="sphere" />
* </Entity>
*
* @param {EntityProps} props - Component props
*/
export declare const Entity: import("react").ForwardRefExoticComponent<EntityProps & import("react").RefAttributes<PcEntity>>;
type PointerEventCallback = (event: SyntheticPointerEvent) => void;
type MouseEventCallback = (event: SyntheticMouseEvent) => void;
export interface EntityProps extends Partial<PublicProps<PcEntity>> {
/**
* The name of the entity
* @default "Untitled"
*/
name?: string;
/**
* The local position of the entity relative to its parent.
* You can use the `position` prop to set the position of the entity.
* @default [0, 0, 0]
*/
position?: [number, number, number];
/**
* The local scale of the entity relative to its parent.
* You can use the `scale` prop to set the scale of the entity.
* @default [1, 1, 1]
*/
scale?: [number, number, number];
/**
* The local rotation of the entity relative to its parent.
* The rotation is specified as euler angles in degrees.
* @default [0, 0, 0]
*/
rotation?: [number, number, number];
/**
* The callback for the pointer up event
* @param {SyntheticPointerEvent} event - The pointer up event
* @default null
*/
onPointerUp?: PointerEventCallback;
/**
* The callback for the pointer down event
* @param {SyntheticPointerEvent} event - The pointer down event
* @default null
*/
onPointerDown?: PointerEventCallback;
/**
* The callback for the pointer over event
* @param {SyntheticPointerEvent} event - The pointer over event
* @default null
*/
onPointerOver?: PointerEventCallback;
/**
* The callback for the pointer out event
* @param {SyntheticPointerEvent} event - The pointer out event
* @default null
*/
onPointerOut?: PointerEventCallback;
/**
* The callback for the click event
* @param {SyntheticMouseEvent} event - The click event
* @default null
*/
onClick?: MouseEventCallback;
children?: ReactNode;
}
export {};