Git Product home page Git Product logo

binvox-rw-py's Introduction

binvox-rw-py

Small Python module to read and write .binvox files. The voxel data is represented as dense 3-dimensional Numpy arrays in Python (a direct if somewhat wasteful representation for sparse models) or as an array of 3D coordinates (more memory-efficient for large and sparse models).

Binvox is a neat little program to convert 3D models into binary voxel format. The .binvox file format is a simple run length encoding format described here.

Code example

Suppose you have a voxelized chair model, chair.binvox (you can try it on the one in the repo). Here's how it looks in viewvox:

chair

Then

>>> import binvox_rw
>>> with open('chair.binvox', 'rb') as f:
...     model = binvox_rw.read_as_3d_array(f)
...
>>> model.dims
[32, 32, 32]
>>> model.scale
41.133000000000003
>>> model.translate
[0.0, 0.0, 0.0]
>>> model.data
array([[[ True, False, False, ..., False, False, False],
        [ True, False, False, ..., False, False, False],
        [ True, False, False, ..., False, False, False],
        ...,
       [[False, False, False, ..., False, False, False],
        [False, False, False, ..., False, False, False],
        [False, False, False, ..., False, False, False],
        ...,
        [False, False, False, ..., False, False, False],
        [False, False, False, ..., False, False, False],
        [False, False, False, ..., False, False, False]]], dtype=bool)

You get the idea. model.data has the boolean 3D array. You can then manipulate however you wish. For example, here we dilate it with scipy.ndimage and write the dilated version to disk:

>>> import scipy.ndimage
>>> scipy.ndimage.binary_dilation(model.data.copy(), output=model.data)
>>> model.write('dilated.binvox')

Then we get a fat chair:

fat chair

Sparse representation

To get the data as an array of coordinates, look at binvox_rw.read_coords.

Installation

This is a really simple, 200-line module. You should just stick into whatever project you're using. Or copy it to /usr/share/lib/pythonX.Y/site-packages if you really want a system-wide installation.


Daniel Maturana [email protected]

mincraft mcpi ready

binvox-rw-py's People

Contributors

dimatura avatar xknxknqq avatar martijnpieters avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.