用户:
萌新大佬查看:6 回复:1 评论:6 创建时间:2022-05-19T15:14:49
function move(bounds,direction,del,deg=0){
var data=[];
for(var i=bounds.lo.x;i<=bounds.hi.x;i++){
var t1=[];
for(var j=bounds.lo.y;j<=bounds.hi.y;j++){
var t2=[];
for(var k=bounds.lo.z;k<=bounds.hi.z;k++){
t2.push([voxels.getVoxelId(i,j,k),voxels.getVoxelRotation(i,j,k)]);
if(del)
voxels.setVoxelId(i,j,k,0);
}
t1.push(t2);
}
data.push(t1);
}
if(!deg){
for(var i=bounds.lo.x;i<=bounds.hi.x;i++){
for(var j=bounds.lo.y;j<=bounds.hi.y;j++){
for(var k=bounds.lo.z;k<=bounds.hi.z;k++){
if(!!data[i-bounds.lo.x][j-bounds.lo.y][k-bounds.lo.z][0]){
voxels.setVoxel(
i+direction.x,j+direction.y,k+direction.z,
data[i-bounds.lo.x][j-bounds.lo.y][k-bounds.lo.z][0],
data[i-bounds.lo.x][j-bounds.lo.y][k-bounds.lo.z][1]
);
}
}
}
}
}else{
for(var i=bounds.lo.x;i<=bounds.hi.x;i++){
for(var j=bounds.lo.y;j<=bounds.hi.y;j++){
for(var k=bounds.lo.z;k<=bounds.hi.z;k++){
if(!!data[i-bounds.lo.x][j-bounds.lo.y][k-bounds.lo.z][0]){
console.log(1);
const p=((i-bounds.lo.x)**2+(k-bounds.lo.z)**2)**0.5;
const angle=Math.atan((i-bounds.lo.x)/(k-bounds.lo.z))+deg;
voxels.setVoxel(
Math.round(p*Math.sin(angle)+bounds.lo.x+direction.x),
j+direction.y,
Math.round(p*Math.cos(angle)+bounds.lo.z+direction.z),
data[i-bounds.lo.x][j-bounds.lo.y][k-bounds.lo.z][0],
data[i-bounds.lo.x][j-bounds.lo.y][k-bounds.lo.z][1]
);
}
}
}
}
}
}
move({lo:{x:61,y:9,z:42},hi:{x:65,y:12,z:46}},{x:1,y:1,z:1},true,Math.PI);
参数一:移动的区域 bounds : Box3Bounds3
参数二:xyz方向移动距离 direction : Box3Vector3
参数三:是否删除原物体 del : Boolean
参数四:绕xyz最小点旋转角度(弧度制)deg : ?Number
角度最好就填九十度(π/2)或者一百八十度(π/2)之类的,否则会出现莫名的喵以及变形(求大佬们提供解决办法)
要注释的评论区里说