#minecraft #merge #blocks #collision #mca #cuboids #block-coordinates

nightly mca-cuboids

从 mca 文件合并方块

2 个不稳定版本

0.2.0 2022 年 8 月 5 日
0.1.0 2022 年 8 月 1 日

471游戏

Apache-2.0/MIT

27KB
672 代码行

mca-cuboids

crates.io

一个简单的工具,将您的 Minecraft 世界中的方块合并成尽可能少的立方体。

示例用法

use mca_cuboids::{BlockCoordinates, ExportParams};

let collisions = mca_cuboids::export_cuboids(
                        "dbg_lvl/region",
                        ExportParams {
                            start: BlockCoordinates::new(0, -64, 0),
                            end: BlockCoordinates::new(64, 0, 64),
                            ..Default::default()
                        },
                    ).expect("Failed to build collisions")
                    
for shape in collisions {
        let x_width = shape.end.x as f32 - shape.start.x as f32 + 1.0;
        let z_width = shape.end.z as f32 - shape.start.z as f32 + 1.0;
        let y_height = shape.end.y as f32 - shape.start.y as f32 + 1.0;

        commands
            .spawn_bundle((
                Transform::from_xyz(
                    shape.end.x as f32 - x_width / 2.0 + 0.5,
                    shape.end.y as f32 - y_height / 2.0 + 0.5,
                    shape.end.z as f32 - z_width / 2.0 + 0.5,
                ),
                GlobalTransform::identity(),
            ))
            .insert(RigidBody::Static)
            .insert(CollisionShape::Cuboid {
                half_extends: Vec3::new(x_width / 2.0, y_height / 2.0, z_width / 2.0),
                border_radius: None,
            });
    }

原始 img_1.png 使用 bevy + heron(CollisionShape::Cuboid + debug-3d 功能) 渲染的结果 img.png

依赖项

~15MB
~78K SLoC