Skip to content

Teddy-van-Jerry/cubeforge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CubeForge

License: MIT Python Version

CubeForge is a Python library designed to easily generate 3D mesh files (currently STL format) by defining models voxel by voxel. It allows for flexible voxel dimensions and positioning using various anchor points.

Features

  • Voxel-based Modeling: Define 3D shapes by adding individual voxels (cubes).
  • Non-Uniform Voxel Dimensions: Specify default non-uniform dimensions for a model, and override dimensions on a per-voxel basis.
  • Flexible Anchoring: Position voxels using different anchor points (cubeforge.CubeAnchor) like corners or centers.
  • STL Export: Save the generated mesh to both ASCII and Binary STL file formats.
  • Simple API: Easy-to-use interface with the core cubeforge.VoxelModel class.

Installation

Install from PyPI: You can install CubeForge directly from PyPI using pip:

pip install cubeforge

Install from source: You can also clone the repository and install the package using pip:

pip install .

Usage

Here's a basic example of how to create a simple shape and save it as an STL file:

import cubeforge
import os

# Create a model with default 1x1x1 voxel dimensions
model = cubeforge.VoxelModel()

# Add some voxels using the default CORNER_NEG anchor
model.add_voxel(0, 0, 0)
model.add_voxel(1, 0, 0)
model.add_voxel(1, 1, 0)

# --- Or add multiple voxels at once ---
# model.add_voxels([(0, 0, 0), (1, 0, 0), (1, 1, 0)])

# --- Example with custom dimensions per voxel ---
tower_model = cubeforge.VoxelModel(voxel_dimensions=(1.0, 1.0, 1.0))
# Add a 1x1x1 base cube centered at (0,0,0)
tower_model.add_voxel(0, 0, 0, anchor=cubeforge.CubeAnchor.CENTER)
# Stack a wide, flat 3x0.5x3 cube on top of it
tower_model.add_voxel(0, 0.5, 0, anchor=cubeforge.CubeAnchor.BOTTOM_CENTER, dimensions=(3.0, 0.5, 3.0))

# Define output path
output_dir = "output"
os.makedirs(output_dir, exist_ok=True)
output_filename = os.path.join(output_dir, "my_shape.stl")

# Save the mesh as a binary STL file
model.save_mesh(output_filename, format='stl_binary', solid_name="MyCustomShape")

print(f"Saved mesh to {output_filename}")

Examples

The examples/create_shapes.py script demonstrates various features, including:

  • Creating simple and complex shapes.
  • Using different default voxel dimensions.
  • Overriding dimensions for individual voxels.
  • Utilizing various CubeAnchor options.
  • Saving in both ASCII and Binary STL formats.
  • Generating a surface with random heights.

To run the examples:

python examples/create_shapes.py

The output STL files will be saved in the examples directory.

API Overview

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests on the GitHub repository.

License

This project is licensed under the MIT License.

This project is developed and maintained by Teddy van Jerry (Wuqiong Zhao). The development is assisted by Gemini 2.5 Pro.

About

Python library to generate 3D (STL) files from cube definitions

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages