player-react
API

API

Player Component Props

NameDescriptionTypeDefaultRequired
src.iplayer file URLstringtrue
onClickClick callback(params: ClickParams) => voidundefinedfalse
onReadyReady callback(instance:ICraftPlayerInstance) => voidundefinedfalse
addonsAddonsReact.ReactNode | AddonKeys[]undefinedfalse
defaultCustomCameraDefault custom camera indexnumberfalse
defaultAnimationPlanDefault animation plan indexnumberfalse
defaultLoopDefault loop playbackbooleanfalsefalse
autoPlayAuto playbackbooleanfalsefalse
localeInternationalization'zh-CN' | 'en-US' | Record<string,LocaleInterface>'en-US'false

TypeScript Types

interface ClickParams {
  instance: Element3D | null;
  event: MouseEvent;
  data: OptionsType | null;
}
 
type AddonKeys = "CameraBar" | "PlayerBar" | "EnterSubScene" | "ZoomBar" | "ExitSubScene";

Player Instance Methods

NameDescriptionType
getDomGet DOM() => HTMLElement
getElementByKeyGet element by unique key(key: string) => Element3D | undefined
getElementsByNameGet multiple elements by name(name: string) => Element3D[]
getCurrentSceneElementsGet all element instances in current scene (excluding sub-scenes)() => Element3D[]
getAllSceneElementsDataGet all element data in current scene (including sub-scenes)() => ElementData[]
playAnimationByElementKeyExecute built-in animation on element(elementKey: string,animationOptions: AnimationActionOptions) => void
cancelAnimationCancel all animations() => void
toogleViewToggle 2D/3D view(is3D: boolean) => void
toogleCameraToggle camera type (perspective | orthographic)(isPerspectiveCamera: boolean) => void
toogleAutoRotateToggle auto-rotation(isAutoRotate: boolean) => void
updateAutoRotateSpeedUpdate auto-rotation speed(speed: number) => void
changeCustomCameraSwitch custom camera(index: number) => void
enterSubSceneEnter sub-scene of current selected element() => void
exitSubSceneExit sub-scene() => void
tooglePlayToggle play() => void
prevStepPrevious step() => void
nextStepNext step() => void
replayReplay() => void
resetReset() => void
toggleLoopToggle loop() => void
zoomInZoom in() => void
zoomOutZoom out() => void
resetCameraReset camera view() => void
exportImageExport image()=>void

TypeScript Types

// Element type
type Element3D =
  | Cube
  | Cylinder
  | Text
  | Area
  | Icon
  | Line
  | Point
  | Model
  | CustomModel
  | ImageModel
  | Image;
 
// Element data
interface ElementData {
  key: string;
  type: string;
  options: OptionsType;
}
 
// Animation action options
interface AnimationActionOptions {
  // Animation type
  animationType?: AnimationType;
  // Animation duration
  animationDuration?: number;
  // Animation delay
  animationDelay?: number;
  // Show dynamic tip
  animationShowTip?: boolean;
  // Narration text
  tipContent?: string | HTMLElement;
  // Narration text color
  tipBackground?: string;
  // Flow line color (line elements only)
  flowLineColor?: string;
  // Flow line thinness factor (controls middle section contraction, higher value means more prominent middle section)
  flowLineThinness?: number;
  // Flow line size factor (controls overall line thickness)
  flowLineSize?: number;
}
 
// Animation type
enum AnimationType {
  // Fade in (non-line elements only)
  FadeIn = "fadeIn",
  // Fade out (non-line elements only)
  FadeOut = "fadeOut",
  // Float up/down (non-line elements only)
  UpAndDown = "upAndDown",
  // Heartbeat (non-line elements only)
  HeartBeat = "heartBeat",
  // Color change (non-line elements only)
  ColorChange = "colorChange",
  // Bounce (non-line elements only)
  Bounce = "bounce",
  // Rotate (non-line elements only)
  Rotate = "rotate",
  // Enter sub-scene (non-line elements only)
  EnterSubScene = "enterSubScene",
  // Exit sub-scene (non-line elements only)
  ExitSubScene = "exitSubScene",
  // Draw animation (line elements only)
  Draw = "draw",
  // Flow animation (line elements only)
  Flow = "flow",
  // Loop flow (line elements only)
  LoopFlow = "loopFlow",
}
 
// Custom locale
interface LocaleInterface {
  cameraBar: {
    speed: string;
    orthographicCamera: string;
    perspectiveCamera: string;
    autoRotate: string;
  };
  playerBar: {
    replay: string;
    pause: string;
    play: string;
    prev: string;
    next: string;
    loop: string;
    reset: string;
  };
  enterSubScene: string;
  exitSubScene: string;
  zoomBar: {
    zoomIn: string;
    zoomOut: string;
    resetCamera: string;
  };
}

Element3D Instance Methods

NameDescriptionType
setDisabledSet disabled state (grayed out)(disabled: boolean) => void