Skip to content

Generate a structure model in python using Blender as a module and export the Blender file.

License

Notifications You must be signed in to change notification settings

polymitis/bpy_gen_structure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Logo image

bpy_gen_structure

Generate a 3-D structure model using Blender as a Python module and export the model in a Blender file.

1 Specify the desired structure

-f or --floorplan accepts a text file path containing the structure floor plan specification. The script doesn't case about the file ending as long as is text readable. The specification has the format of a 2-D matrix depicting the structure floor plan. Only single level structures are supported.

The elements of the matrix denote:

  • the start of wall panels 1
  • the restart of a wall panels -1
  • the absence of wall panels 0.

A wall are constructed by assembling panels:

  • A wall panel requires at least two matrix element points, the first can be either a start or restart and the next must be a start.
  • If a start follows, then the wall is extended by another panel in any of the orthogonal directions (up,down,left, right).
  • If an absence or a restart follows, then no wall panel is added and the wall ends.

Look at the following examples and try to imagine walls between the 1 1 or -1 1 and wall gaps between 1 -1. All 0 are empty space.

Example 1: A walled garden with a single entrance.

1  1  1  1  1
1  0  0  0  1
1  1  0  1  1

Example 2: A square room with a single entrance.

1  1  1  1
1  0  0  1
1  1 -1  1

Example 3: A walled garden with a studio house in the middle left and a garage at the top right side.

1  1  1  1  1  1  1  1  1  1
1  0  0  0  0  0  0  1  0  1
1  0  1  1  1  1  0  1  0  1
1  0  1  0  0  1  0  1  0  1
1  0  1  1 -1  1  0  0  0  1
1  0  0  0  0  0  0  0  0  1
1  1  1  1  1  1  1  1  0  1

2 Choose the building primitives

-p or --panel accepts a glTF model file path and trusts the model to be a panel with dimensions of x:1, y:10, z:30.

3 Choose Blender model output directory

-s or --save accepts a Blender file path to write the generated 3-D structure model.

4 Run the script

Run the generator with blender in background mode:

  blender --background --factory-startup \
  --python $HOME/bpy_gen_structure.py -- \
  --floorplan=$specs/room.dat \
  --panel=$primitives/panel.glb \
  --save=$models/room.blend

or run the generator using Blender as a Python module:

  python $HOME/bpy_gen_structure.py \
  --floorplan=$specs/room.dat \
  --panel=$primitives/panel.glb \
  --save=$models/room.blend

Notice:

  • --factory-startup is used to avoid the user default settings from interfering with automated scene generation.
  • -- causes blender to ignore all following arguments so python can use them.
  • Using Blender as a Python module requires to build Blender from source and install bpy python module in the current python environment, see official guide.

See blender --help for details.

About

Generate a structure model in python using Blender as a module and export the Blender file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages