player-javascript
API

API

ICraftPlayerOptions

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

TypeScript Types

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

Player Instance Methods

NameDescriptionType
getDomGet DOM() => HTMLElement
getElementByKeyGet element by unique key(key: string) => Element3D or 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: GlobalAnimationOptions) => Promise<Actuator | null>
cancelAnimationByElementKeyCancel animation by element key(elementKey: string) => void
cancelAnimationCancel all animations() => void
toogleViewToggle 2D/3D view(is3D: boolean) => void
toogleCameraToggle camera type (perspective or orthographic)(isPerspectiveCamera: boolean) => void
toogleAutoRotateToggle auto-rotation(isAutoRotate: boolean) => void
updateAutoRotateSpeedUpdate auto-rotation speed(speed: number) => void
changeCustomCameraSwitch custom camera(index: number, duration?: number) => void
enterSubSceneEnter sub-scene of current selected element(durations?: number) => Promise<void>
exitSubSceneExit sub-scene() => Promise<void>
tooglePlayToggle play() => void
prevStepPrevious step() => Promise<void>
nextStepNext step() => Promise<void>
replayReplay() => Promise<void>
resetReset() => Promise<void>
toggleLoopToggle loop() => void
zoomInZoom in() => void
zoomOutZoom out() => void
resetCameraReset camera view() => void
exportImageExport image() => Promise<void>
openFileByUrlOpen file by URL(url: string, options?: RequestInit) => void

TypeScript Types

// Element data
interface ElementData {
  key: string;
  type: string;
  options: OptionsType;
}
 

Player Static Methods

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

TypeScript Types

interface StaticConfig {
  // Global font resource path, affects all text elements, highest priority, suitable for scenarios with only one font
  fontUrl?: string;
  // Global font resource definition, suitable for scenarios with multiple fonts
  fonts?: FontFamily[];
  // Draco Decoder Path, The default path is unpkg. If the network is not accessible, you can configure the path yourself.
  dracoDecoderPath?: string;
}
 
export interface FontFamily {
  name: string;
  styles: {
    weight: string;
    fontUrl: string;
  }[];
}

Element3D Instance Methods

NameDescriptionType
setDisabledSet disabled state (grayed out)(disabled: boolean) => void
setVisibleSet element visibility(visible: boolean) => void