我正在创建爆炸和内爆的按钮,将场景中的所有网格物体移离 如您所见,从边界框的中心开始。爆炸按钮适用于我所有的网格 对象,但内爆按钮不会将我的网格物体带到先前的位置。也许物理学是问题,我希望任何人都能帮忙。
function explodeObjects() {
var boundingbox = new THREE.Box3();
for (var i = 0; i < scene.children.length; i++) {
if (scene.children[i] instanceof THREE.Mesh) {
var mesh = scene.children[i];
var position = scene.children[i].position;
var distance = 5;
var direction = position.clone().normalize();
pointNew = position.clone().addScaledVector(direction,distance);
var x = Math.trunc(pointNew.x,);
var y = Math.trunc(pointNew.y);
var z = Math.trunc(pointNew.z);
stepToExplode(mesh,x,y,z);
}
}
function stepToExplode(mesh,z) {
var tween = new TWEEN.Tween(mesh.position).to({
x: x,y: y,z: z
},2000).start();
tween.easing(TWEEN.Easing.Linear.None);
}
}
function implodeObjects() {
var boundingbox = new THREE.Box3();
for (var i = 0; i < scene.children.length; i++) {
if (scene.children[i] instanceof THREE.Mesh) {
boundingbox.expandByObject(scene.children[i]);
}
}
for (var i = 0; i < scene.children.length; i++) {
if (scene.children[i] instanceof THREE.Mesh) {
var from = boundingbox.getcenter(new THREE.Vector3());
var mesh = scene.children[i];
var position = scene.children[i].position;
var distance = 5;
var direction = position.clone().normalize();
var pointNew = position.clone().addScaledVector(direction,);
var y = Math.trunc(pointNew.y);
var z = Math.trunc(pointNew.z);
stepToImplode(from,mesh,z)
}
}
function stepToImplode(from,z) {
var tween2 = new TWEEN.Tween(mesh.position).to({
x: mesh.position.x - x,y: mesh.position.y - y,z: mesh.position.z - z
},2000).start();
tween2.easing(TWEEN.Easing.Linear.None);
}
}