1,介绍
该示例使用的是 r95版本Three.js库。
主要实现功能:引入机械臂dae格式模型,模拟机械臂运动。效果图如下:
?2,动画主要说明
1,引入机械臂模型,附模型下载地址如下
2,使用Tween.js模拟实现动画
// 添加坊的模型
function initFang() {
var loader = new THREE.ColladaLoader();
loader.load('assets/models/abb_irb52_7_120.dae', function(collada) {
dae = collada.scene;
dae.traverse(function(child) {
if (child.isMesh) {
// model does not have normals
child.material.flatShading = true;
}
});
// dae.scale = 1000;
dae.updateMatrix();
kinematics = collada.kinematics;
console.log(kinematics)
scene.add(dae);
setupTween();
});
}
function setupTween() {
const duration = THREE.Math.randInt(1000, 2000);
const target = {};
for (const prop in kinematics.joints) {
if (kinematics.joints.hasOwnProperty(prop)) {
if (!kinematics.joints[prop].static) {
const joint = kinematics.joints[prop];
const old = tweenParameters[prop];
const position = old ? old : joint.zeroPosition;
tweenParameters[prop] = position;
target[prop] = THREE.Math.randInt(joint.limits.min, joint.limits.max);
}
}
}
kinematicsTween = new TWEEN.Tween(tweenParameters).to(target, duration).easing(TWEEN.Easing.Quadratic.Out);
kinematicsTween.onUpdate(function(object) {
for (const prop in kinematics.joints) {
if (kinematics.joints.hasOwnProperty(prop)) {
if (!kinematics.joints[prop].static) {
kinematics.setJointValue(prop, this[prop]);
}
}
}
});
kinematicsTween.start();
setTimeout(setupTween, duration);
}
Threejs模型,机械臂模型,dae格式模型-Javascript文档类资源-CSDN文库https://download.csdn.net/download/baidu_29701003/85335014
|