player-react
Animation
builtin

Built-in Animations

We have built-in animation types that can be executed on elements by calling the player instance method playAnimationByElementKey. Each animation type has its applicable element types and specific parameter configurations.

How to Use

After obtaining the player instance through ref or onReady, call the playAnimationByElementKey method with the element's key and animation parameters to execute animations. Use the cancelAnimation method to cancel currently playing animations.

import {
  AnimationType,
  MouseEventParams,
  ICraftPlayer,
  ICraftPlayerInstance,
} from "@icraft/player-react";
import React from "react";
 
const style = {
  width: "100%",
  height: "100%",
  position: "relative" as const,
  overflow: "hidden" as const,
};
 
export default () => {
  const playerRef = React.useRef<ICraftPlayerInstance>();
 
  const onClick = (e: MouseEventParams) => {
    const player = playerRef.current;
    const { instance: Element } = e;
    if (!Element) {
      player?.cancelAnimation();
      return;
    }
    // Choose appropriate animation based on element type
    if (Element.typeName === "tube") {
      player?.playAnimationByElementKey(Element.key, {
        animationDuration: 4,
        animationType: AnimationType.TubeZebraFlow,
        colorPrimary: "#0066ff",
        speed: 2.0,
      });
    } else if (Element.typeName === "line") {
      player?.playAnimationByElementKey(Element.key, {
        animationDuration: 3,
        animationType: AnimationType.LoopFlow,
        flowLineColor: "#00ff88",
      });
    } else {
      player?.playAnimationByElementKey(Element.key, {
        animationDuration: 3,
        animationType: AnimationType.HeartBeat,
        animationShowTip: true,
      });
    }
  };
 
  return (
    <div style={style}>
      <ICraftPlayer
        src='/templates/AWSCloud.iplayer'
        onClick={onClick}
        ref={playerRef}
      />
    </div>
  );
};

API

Functions

Namedescriptiontype
getElementsByNameGet multiple elements by name(name: string) => Element3D[]
playAnimationByElementKeyExecute built-in animation(elementKey: string,animationOptions: GlobalAnimationOptions) => void
cancelAnimationCancel all animations() => void

General Element Animations

Applicable to general element types such as cube, cylinder, sphere, prism, cone, torus, model, imagemodel, custommodel, icon, image, text, text3d, svg, etc.

FadeIn

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"fadeIn"true
animationDurationDuration (seconds)number2true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse

FadeOut

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"fadeOut"true
animationDurationDuration (seconds)number2true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse

UpAndDown

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"upAndDown"true
animationDurationDuration (seconds)number3true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse

HeartBeat

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"heartBeat"true
animationDurationDuration (seconds)number2true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse

Bounce

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"bounce"true
animationDurationDuration (seconds)number2true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse

Rotate

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"rotate"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse

EnterSubScene

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"enterSubScene"true
animationDurationDuration (seconds)number1true
animationDelayDelay (seconds)number0false

ExitSubScene

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"exitSubScene"true
animationDurationDuration (seconds)number1true
animationDelayDelay (seconds)number0false

BreathingWireframe

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"breathingWireframe"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse
speedSpeednumber2.0false
colorPrimaryColorstring#ffee00false
breathingFrequencyBreathing Frequencynumber2false
widthLine Widthnumber0.05false

FlowWireframe

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"flowWireframe"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse
speedSpeednumber2.0false
colorPrimaryColorstring#ffee00false
widthLine Widthnumber0.05false

PulseRing

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"pulseRing"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleantruefalse
colorPrimaryColorstring#00fffffalse
pulseFrequencyPulse Frequency (seconds)number0.3false
maxRadiusMax Spread Radiusnumber10.0false

Line Element Animations

Applicable to line line element type.

Draw

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"draw"true
animationDurationDuration (seconds)number3true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleanfalsefalse
tipContentTip Contentstring''false
tipBackgroundTip Background Colorstring#fffffffalse
tipHeightTip Heightnumber1.4false

Flow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"flow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
animationShowTipShow Dynamic Tipbooleanfalsefalse
tipContentTip Contentstring''false
tipBackgroundTip Background Colorstring#fffffffalse
tipHeightTip Heightnumber1.4false
flowLineColorFlow Line Colorstring#18A1FFfalse
flowLineThinnessFlow Line Thinness, controls middle contractionnumber0.5false
flowLineSizeFlow Line Length, controls overall lengthnumber0.3false

LoopFlow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"loopFlow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
flowLineColorFlow Line Colorstring#18A1FFfalse
flowLineThinnessFlow Line Thinness, controls middle contractionnumber0.5false
flowLineSizeFlow Line Length, controls overall lengthnumber0.3false

Tube Element Animations

Applicable to tube tube element type.

TubeGasFlow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"tubeGasFlow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
speedFlow Speednumber2.0false
colorPrimaryPrimary Colorstring#00227efalse
colorSecondarySecondary Colorstring#0243f4false

TubeZebraFlow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"tubeZebraFlow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
speedFlow Speednumber1false
colorPrimaryPrimary Colorstring#0066fffalse
colorSecondarySecondary Colorstring#fffffffalse
stripeWidthStripe Lengthnumber1false

TubeFoamFlow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"tubeFoamFlow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
speedFlow Speednumber0.1false
foamDensityFoam Densitynumber30false
colorPrimaryPrimary Colorstring#0243f4false
colorSecondarySecondary Colorstring#85a5fffalse
pulseIntensityPulse Intensitynumber0.1false

TubeArrowFlow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"tubeArrowFlow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
speedFlow Speednumber1.5false
arrowSizeArrow Sizenumber0.25false
arrowCountArrow Countnumber8false
colorPrimaryArrow Colorstring#246af7false

TubeEnergyFlow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"tubeEnergyFlow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
speedFlow Speednumber3.0false
colorPrimaryPrimary Colorstring#0044fffalse
colorSecondarySecondary Colorstring#0088fffalse

TubeElectronFlow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"tubeElectronFlow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
speedFlow Speednumber2.0false
colorPrimaryPrimary Colorstring#000000false
electronDensityElectron Densitynumber16false

TubeLightFlow

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"tubeLightFlow"true
animationDurationDuration (seconds)number4true
animationDelayDelay (seconds)number0false
speedFlow Speednumber2.0false
colorPrimaryPrimary Colorstring#0243f4false
colorSecondarySecondary Colorstring#cbdcfffalse

Camera Animations

Special camera control animations.

Camera

Namedescriptiontypedefaultrequired
animationTypeAnimation TypeAnimationType"camera"true
animationDurationDuration (seconds)number2true
animationDelayDelay (seconds)number0false
cameraDataCamera PositionCameraDataundefinedtrue
interface CameraData {
  key: string; // Unique camera identifier
  type: string; // Camera type
  position: number[]; // Camera position coordinates [x, y, z]
  target: number[]; // Camera target coordinates [x, y, z]
  zoom: number; // Zoom level
  quaternion?: number[]; // Camera rotation quaternion [x, y, z, w]
}