用户:
某只sans喵呀查看:51 回复:11 评论:51 创建时间:2022-06-11T12:04:02
建筑师在线求助,
如何在一片圆柱体中的air全部替换成water,
用手搭了一天,就只搭了一点

最好是给我代码呀
你用的是手机吗imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%BF%BB%E7%99%BD%E7%9C%BC.gif"alt="emotion_编程猫_翻白眼"
点赞0
评论
VisualProgramer试试这个
/* 在指定位置快速建造一个圆柱体 */
function cylinder(vox, cx, cy, cz, radius, height){
let xend = cx+radius
let yend = cy+height
let zend = cz+radius
for(let x=cx-radius; x<=xend; x++){
for(let z=cz-radius; z<=zend; z++){
let dx = x-cx;
let dz = z-cz;
if(Math.round(Math.sqrt(dx*dx+dz*dz)) <= radius){
for(let y=cy; y<yend; y++){
voxels.setVoxel(x,y,z,vox)
}
}
}}
}
cylinder('stone',63,12,63,10,4) // 调用方法。在{x:63, y:12, z:63} 位置,建造一个半径10格,高度4格的圆柱体点赞0
评论
调皮的乔治for(let x=0;x<126;x++){; //x坐标的初始与结尾
for(let y=3;y<9;y++){; //y坐标的初始与结尾
for(let z=0;z<126;z++){; //z坐标的初始与结尾
let num = voxels.getVoxel(x,y,z); //获取当前方块id
if (num == 0){; //判断当前方块是否为air
voxels.setVoxel(x,y,z,"water"); //将当前方块转换为water
};
};
};
};点赞0
评论
VisualProgramer let num = voxels.getVoxel(x,y,z); //获取当前方块id
if (num == 0){; //判断当前方块是否为air
function cylinder(vox, cx, cy, cz, radius, height){
let xend = cx+radius
let yend = cy+height
let zend = cz+radius
for(let x=cx-radius; x<=xend; x++){
for(let z=cz-radius; z<=zend; z++){
let dx = x-cx;
let dz = z-cz;
if(Math.round(Math.sqrt(dx*dx+dz*dz)) <= radius){
for(let y=cy; y<yend; y++){
voxels.setVoxel(x,y,z,vox)
}
}
}}
}
}
cylinder('stone',63,12,63,10,4) // 调用方法。在{x:63, y:12, z:63} 位置,建造一个半径10格,高度4格的圆柱体
这应该是圆柱体
点赞0
评论