加载fbx模型
加载fbx格式三维模型,用户可对模型进行一些列的交互式操作,以及开启模型的动画。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>加载fbx模型</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"/>
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
<script src="https://delivery.mapmost.com/cdn/sdk/webgl/v9.1.1/mapmost-webgl-min.js"></script>
</head>
<body>
<div id="map"></div>
<script>
let map = new mapmost.Map({
container: 'map',
style: "<your style url>",
center: [120.67400351817594, 31.321374251251726],
zoom: 15.310035105070947,
pitch: 59.48725112156901,
bearing: -54.10626584095007,
userId: '***', // 授权码
env3D: {
envMap: '../example_data/hdr/venice_sunset_2k_fixed5_1.hdr'
}
});
const THREE = mapmost.THREE;
map.on('load', function () {
let models_obj = ["../example_data/Samba Dancing.fbx"].map(item => ({
type: 'fbx',
url: item
}));
let mixer;
const clock = new THREE.Clock()
let options = {
id: 'model_id',
type: 'model',
models: models_obj,
funcRender: function () {
const time = clock.getDelta();
if (mixer) {
mixer.update(time);
}
},
center: [120.67727020663829, 31.31997024841401],
callback: function (group, layer) {
// 开启模型动画
let object = group.children[0];
mixer = new THREE.AnimationMixer(object);
const action = mixer.clipAction(object.animations[0]);
// action.setLoop(THREE.LoopOnce); // 设置只播放一次
action.play();
object.traverse(function (child) {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
}
};
map.addLayer(options);
})
</script>
</body>
</html>