videx-3d
Version:
React 3D component library designed for sub surface visualizations in the browser
60 lines (59 loc) • 1.89 kB
TypeScript
import { ReactNode } from 'react';
import { BufferGeometry, Material, Object3D } from 'three';
/**
* EventEmitter props
* @expand
*/
export type EventEmitterProps = {
threshold?: 1 | 2 | 3;
children?: ReactNode;
};
export type RenderableObject = Object3D & {
material: Material;
geometry: BufferGeometry;
};
export type Emitter = {
source: RenderableObject;
depth: number;
material: Material;
listener: number;
instanced?: boolean;
instanceColor?: Float32Array;
};
export type ObjectMapEntry = {
emitter: Emitter;
index?: number;
};
export type ObjectMap = {
map: Map<number, ObjectMapEntry>;
index: number;
};
/**
* The EventEmitter provider component allow child components to register as an event emitter.
* Event emitter objects are rendered offscreen every frame and tested for proximity to the pointer location (i.e. mouse cursor).
*
* Each object is asigned an unique color, using an override material, and a small area
* is rendered around the pointer. The rendered framebuffer is returned from the GPU and
* processed on the CPU side to detect pointer events, such as pointer click, pointer enter,
* pointer exit and pointer move.
*
* This allows for a more performant interaction model (than using raycasting) when there are
* a large number of objects that needs to be tested.
*
* To add a component as an event emitter, use the `useEventEmitter` hook.
*
* @example
* <EventEmitter>
* { children }
* </EventEmitter>
*
* @remarks
* When a component is added as an event emitter, the entire object graph is added by default.
* Objects may be excluded by assigning it the `NOT_EMITTER` layer.
*
* @see {@link useEventEmitter}
* @see {@link LAYERS}
*
* @group Components
*/
export declare const EventEmitter: ({ threshold, children }: EventEmitterProps) => import("react/jsx-runtime").JSX.Element;