Skip to content

A port of Botffy/polyskel library for Blender that outputs polygons formed by a straight skeleton. 'pip install mathutils' to use it as a general purpose library independent of Blender.

License

Notifications You must be signed in to change notification settings

prochitecture/bpypolyskel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bpypolyskel

Logo

How to fit a hipped roof to the walls of a building? No problem, the bpypolyskel library provides a single function that does the whole task automatically. From the footprint of a building, its straight skeleton gets computed. From this skeleton all faces get extracted and the height for every vertex of the straight skeleton is calculated. All these computations can easily be done in Blender, but the library may also be used in general purpose applications.

The bpypolyskel library was tested against all 320.000 hipped roofs in the OpenStreetMap database. It runs successfully for 99.99% of them.

Usage

The library bpypolyskel provides two functions:

  • polygonize()

polygonize() is the main function to compute the faces of a hipped roof from the footprint of a building, it does the whole task described above. It accepts a simple description of the contour of the footprint polygon, including those of eventual holes, and returns a list of polygon faces. See more details in its documentation.

  • skeletonize()

skeletonize() creates the straight skeleton of the footprint. It gets a list of the edges of the footprint polygon, including those of eventual holes, and creates a straight skeleton. This function is called from polygonize(), but may also be used independantly. See more details in its documentation

Note

The straight skeleton computed by skeletonize() does not provide a straight skeleton in a mathematical sense. Several cleaning and merging algorithms repair issues produced by inaccuracies of the footprint and issues in the skeletonize algorithm. Its goal is to create a skeleton that fits best for a hipped roof.

Installation and Demos

You find all required files in the folder bpypolyskel. There are two main applications of this project:

Within a Blender addon

Copy the whole folder bpypolyskel to your addon. Include the functions using

from .bpypolyskel import bpypolyskel

The file __init__.py shows a simple code for usage in an addon. It adds an object created by bpypolyskel to a scene. The demo object is created in Blender by Add -> Mesh -> Add bpypolyskel Demo Object.

General purpose application

The functions of bpypolyskel are also usable using a Python interpreter, but then the installation of the package mathutils is required. Install it using:

pip install mathutils

A simple demo in the file demo.py shows this type of usage and displays the result using matplotlib.

Credits

The implementation of the straight skeleton algorithm is based on the description by Felkel and Obdržálek in their 1998 conference paper Straight skeleton implementation. The code for the function skeletonize() has been ported from the implementation by Botffy.

The main adaptions compared to Botffy's original code are:

  • The order of the vertices of the polygon has been changed to a right-handed coordinate system (as used in Blender). The positive x and y axes point right and up, and the z axis points into your face. Positive rotation is counterclockwise around the z-axis.
  • The geometry objects used from the library euclid3 in the implementation of Bottfy have been replaced by objects based on mathutils.Vector. These objects are defined in the new library bpyeuclid.
  • The signature of skeletonize() has been changed to lists of edges for the polygon and eventual hole. These are of type Edge2, defined in bpyeuclid.
  • Some parts of the skeleton computations have been changed to fix errors produced by the original implementation.
  • Algorithms to merge clusters of skeleton nodes and to filter ghost edges have been added.
  • A pattern matching algorithm to detect apses, that creates a multi-edge event to create a proper apse skeleton.

About

A port of Botffy/polyskel library for Blender that outputs polygons formed by a straight skeleton. 'pip install mathutils' to use it as a general purpose library independent of Blender.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages