(WARNING The implementation of this operator is based on an inspection of Blender source code. It just works but does not reflect the suggested usage from the design.)
In this post I will take an experiment on generating mesh dynamically in Blender.
As I said in the previous post
there are two possible approaches to generate mesh data dynamically.
One is to add a new BMesh operator which is similar to
The other is
to construct a
Mesh(defined in the file
and apply the BMesh operator
I will try the later one today.
The major problem of this project is how to construct a
More concretely, you have to search for functions
which can be used as tools to construct a
If you are familiar with the directory structure of Blender,
you would probably make a correct guess that those
Mesh related functions
should be in
blender/source/blender/editors/(The answer is
But you still have to spend time on making sure your way of
applying those functions is correct,
that is, you should provide the correct preconditions for every call.
Instead of the above approach,
I introduce you a way to learn how to construct a
by using Blender’s Python API.
Let us get started.
I assume you are familiar of how to achieve this using Python API:
The most important function is
This function fills the mesh data and build the topology for a mesh.
You can find the implementation of this function
I put an excerpt of its source code below:
All functions called above is implemented in C.
By applying tracing techniques I introduced in
"loop_start" in the source code.
Be sure to include the double quotes while searching
since we are interested in the reflection code with those words),
we can collect all of the information we need to construct a
After that, the remains are simple.
To call a BMesh operator, according our
on BMesh system,
you can find the desired operator name and parameters in
Also do not forget to link the newly created object to the scene, and trigger a notification.
I upload all source code of this experiment here.
In the next post I will write some real code on the contouring algorithm.