代码
import {
  AnimationModel,
  BaiduMapConfig,
  BaiduVectorTileProvider,
  Engine,
  urlUtils,
} from '@baidumap/mapv-three';

BaiduMapConfig.ak = '您的密钥';

const container = document.getElementById('map');
const aspect = container.clientWidth / container.clientHeight;
const center = [116.392, 40.0347];
const engine = new Engine(container, {
  map: {
    projection: 'EPSG:3857',
    center,
    range: 18 / Math.min(1, aspect),
    pitch: 72,
    heading: 20,
    provider: new BaiduVectorTileProvider({
      displayOptions: {
        building: false,
        poi: false,
      },
    }),
  },
  rendering: {
    enableAnimationLoop: true,
  },
});

// 人物模型约 1.8 米高,带一段骨骼动画。
const model = engine.add(
  new AnimationModel({
    name: 'walker',
    point: [...center, 0],
    object: urlUtils.getAssetUrl('assets/models/twin/MINIMALIST/MAN_ANIMATE.glb'),
    autoPlay: true, // 自动播放第一个动画
  }),
);

const toggle = document.getElementById('toggle');
toggle.addEventListener('click', () => {
  const paused = toggle.getAttribute('aria-pressed') !== 'true';
  if (paused) {
    model.stop();
  } else {
    model.play();
  }
  toggle.setAttribute('aria-pressed', String(paused));
  toggle.textContent = paused ? '继续动画' : '暂停动画';
});

用 AnimationModel 加载 SDK 自带的带骨骼动画的人物模型,自动播放动画,可暂停和继续。

预览