Questions about Blender C code

Hi I’m digging into blender c code and I’ll post my questions here for anyone who is willing to help. I guess my questions were too basic for blender.chat to answer. :frowning:

So my question is how do you call for blender operators?
here is a code example from : \blender\source\blender\bmesh\operators\bmo_symmetrize.c

BMO_op_initf(bm,
               &op_bisect,
               op->flag,
               "bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b",
               op,
               "input",
               plane_no,
               dist,
               true,
               true);

  BMO_op_exec(bm, &op_bisect);

so this part of code should initiate and execute mesh bisecting right?
my question is:
is “bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b” is responsible for calling the code for bisecting?
what and where does it call?
bmesh_bisect_plane.h OR bmesh_bisect_plane.c or something else?

cause I don’t think it does. if yes how do you explane this line:

BMO_op_initf(bm, &op_dupe, op->flag, "duplicate geom=%S", &op_bisect, "geom.out");

  BMO_op_exec(bm, &op_dupe);

where does it call for duplicate? I can’t find a clear reference in the code.

sorry if my questions are stupid.

Though I have not participated in Blender source so far, only in terms of function calls. It was a good exercise for me to spend a few minutes and find the answer, now I know something as well too. :slight_smile:

[1]
All the mesh operators are defined here
https://github.com/blender/blender/blob/67f3941dd592d8a02d86450e303b6b7e50857c9c/source/blender/bmesh/intern/bmesh_opdefines.c

The definition of the operator is: bmo_bisect_edges_def which means that it initializes the operator as an object, along with all of the essential configuration.

The implementation of the operator is bmo_bisect_edges_exec and is the exact code how it works is found here.
https://github.com/blender/blender/blob/2d1cce8331f3ecdfb8cb0c651e111ffac5dc7153/source/blender/bmesh/operators/bmo_subdivide.c

[2]
All operator definitions are placed in bmo_opdefines, which is the literal global array with all operators.

const BMOpDefine *bmo_opdefines[] = { ...
    &bmo_bisect_edges_def ...

[3]
When the BMO_op_initf is called it wants to search bmo_opdefines and return the definition.
https://github.com/blender/blender/blob/2d1cce8331f3ecdfb8cb0c651e111ffac5dc7153/source/blender/bmesh/intern/bmesh_operators.c

Other questions:

is “bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b” is responsible for calling the code for bisecting?

This part is a formatted string and the rest after var args. Everything will be used as operator parameters. When the operator gets executed it will use the values to do it’s work.

1 Like

Wow, Thanks man. I have to read you comment more and more to understand it.
so what I learned from you is:
This code:

BMO_op_initf(bm,
               &op_bisect,
               op->flag,
               "bisect_plane geom=%s plane_no=%v dist=%f clear_outer=%b use_snap_center=%b",
               op,
               "input",
               plane_no,
               dist,
               true,
               true);

Will look for This code?

static BMOpDefine bmo_bisect_plane_def = {

  "bisect_plane",
.
.
.

in the “bmesh_opdefines.c”?

I think I cut to many steps but I think I can finally read the code way more better now that I can connect the dots thanks to you!
there is even the

static BMOpDefine bmo_duplicate_def = {
  "duplicate",

code in there so I think that answers my question.
Thanks for your time.

I will ask more questions in this topic if I could not figure them out.
thanks again! :+1:

The only way to understand how the code works is by searching. For example (in github) if you search for bmo_bisect_edges_def you will find a few files that this is either [declared] or [used].

Also another thing I forgot to mention is that operators are setup like having a design pattern (in this case see the command design pattern). Though C is not object oriented, the design principles can be replicated since the ideas universal. This is mostly a matter of convention and architecture.

1 Like