Metadata-Version: 2.4
Name: mesh2brick
Version: 0.1.0
Summary: Convert a 3D object into a brick structure.
Project-URL: Homepage, https://github.com/K1ngHungry/mesh2brick
Project-URL: Repository, https://github.com/K1ngHungry/mesh2brick
Project-URL: Issues, https://github.com/K1ngHungry/mesh2brick/issues
Author-email: Ava Pun <apun@andrew.cmu.edu>, Kevin Dai <kevindai@andrew.cmu.edu>
License-Expression: MIT
License-File: LICENSE
Keywords: 3d,bricks,geometry,lego,mesh,voxel
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Requires-Dist: gurobipy
Requires-Dist: networkx
Requires-Dist: numpy
Requires-Dist: open3d
Requires-Dist: scipy
Description-Content-Type: text/markdown

# mesh2brick

`mesh2brick` is a utility package for converting an input mesh file into a brick structure in JSON, text, or LDraw
format.

## Usage

### Standalone project

To use as a standalone project, first install the package manager [uv](https://docs.astral.sh/uv/). Then, clone the
repository:

```bash
git clone https://github.com/K1ngHungry/mesh2brick.git
cd mesh2brick
```

Finally, run the `mesh2brick` script with the following command. `uv` automatically installs all dependencies upon
running.

```
uv run mesh2brick [INPUT_MESH_FILE] [OUTPUT_BRICK_FILE]
```

The `[INPUT_MESH_FILE]` can be any mesh format (`.obj`, `.glb`, etc.).

The `[OUTPUT_BRICK_FILE]` should end in `.json`, `.txt`, or `.ldr` to specify one of the following three output formats:

- **JSON.** The output JSON maps a 1-based sequence number to each brick. Each brick has the following keys:
    - `brick_id`: A number indicating the brick type. See `brick_library.json` for a list of brick types.
    - `x`, `y`, `z`: The coordinates of the brick in 3D space.
    - `type`: `0` for a regular brick/plate, `1` for a slope brick.
    - `rotation`: `0`–`3`, indicating the orientation of the brick (90° increments).
- **Text.** The output text file is a list of bricks, one per line, with the following format:
  `T{type} {l}x{w}x{h} R{rotation} (x,y,z)`, where `type` is the brick type (`0`=brick/plate, `1`=slope), `l`, `w`, `h`
  are the brick dimensions along the *x*-, *y*-, and *z*-axes, `rotation` is the orientation (`0`–`3`), and `(x,y,z)`
  are the coordinates of the brick in 3D space.
- **LDraw.** The output LDraw file can be used directly with LDraw-compatible software to visualize the brick structure.

Run `uv run mesh2brick --help` to see all available options.

### Python package

To install `mesh2brick` as a package in an existing project, run:

```bash
pip install mesh2brick
```

if using `pip`, or

```bash
uv add mesh2brick
```

if using `uv`.

Then, you can use the `mesh2brick` module in your Python code:

```python
from mesh2brick import Mesh2Brick

input_file = "path/to/your/input_mesh.obj"
mesh2brick = Mesh2Brick()
output_bricks = mesh2brick(input_file)
```