player-javascript
API

API

ICraftPlayerOptions

NameDescriptionTypeDefaultRequired
containerContainer DOMHTMLDivElementtrue
src.iplayer file URLstringtrue
fetchOptionsFetch options for file requestRequestInitundefinedfalse
onClickClick callback(params: ClickParams) => voidundefinedfalse
onReadyReady callback(instance:ICraftPlayerInstance) => voidundefinedfalse
defaultCustomCameraDefault custom camera indexnumberundefinedfalse
defaultAnimationPlanDefault animation plan indexnumberundefinedfalse
defaultLoopDefault loop playbackbooleanfalsefalse
autoPlayAuto playbackbooleanfalsefalse

TypeScript Types

interface ClickParams {
  instance: Element3D | null;
  event: MouseEvent;
  data: OptionsType | null;
}

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
openFileByUrlOpen file by URL(url: string, options?: RequestInit) => 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",
}

Player Static Methods

NameDescriptionType
defineConfigSet static global configuration(config: StaticConfig) => void

TypeScript Types

interface StaticConfig {
  fontUrl?: string;
}

Element3D Instance Methods

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