Skip to content

Conversation

@emil-dietrich
Copy link

@emil-dietrich emil-dietrich commented Oct 20, 2023

Each bone is extracted if the expression returns True.
Each bone is accessible in the expression by the var bone.

  • TODO: compile the expression once and use the bytecode with eval(bytecode, ...)

Each bone is extracted if the expression returns `True`.
Each bone is accessible in the expression by the var `bone`.

TODO: compile the expression once and use the bytecode with
`eval(bytecode, ...)`
@BlenderBoi
Copy link
Owner

Interesting contribution! I will take some time to review the code and test the feature, hopefully it will be a good addition to Game Rig Tools

extract mode cases are handled once, not once per iteration
custom expression is compiled once, not once per iteration
@emil-dietrich
Copy link
Author

For the last commit a8414a8
before:
image
after:
image

xx was what I entered in the input field

@BlenderBoi
Copy link
Owner

I will need some time to check if this is safe

eval seems to have some security risk, I will need some time to research if this is ok to add

@emil-dietrich
Copy link
Author

emil-dietrich commented Nov 1, 2023

If there is a security risk its that you can use python within blender.
Everyone can open a text file in blender and press execute.
To add to it: Only one variable is accessible by the expression and that is bone.
If you have open questions or if theres something unclear you can also ask here. You don't need to investigate alone.

Blender also uses expressions for drivers. They evaluate the python code from C++, but that does not really matter.
https://github.com/blender/blender/blob/01a2bd03695f217616acc2581fe8746f5cd226d7/source/blender/python/intern/bpy_driver.cc#L573

@BlenderBoi
Copy link
Owner

Fair Point, I will do some testing and if it works will I will merge it

@emil-dietrich
Copy link
Author

Dont merge what you dont understand. Dont feel pressured to add this before you are comfortable with the changes.

@emil-dietrich
Copy link
Author

Sry, for another addition:
rigify also dynamically executes python code, see finalize_script property.
It calls it as follows (in generate.py:594): exec(finalize_script.as_string(), {})

(You can see where rigify is located on your hard drive if you go to the preferences -> addons -> rigify -> File: ...)

exec and eval are basically the same, but eval returns a value and exec does not.

The above still applies - if you dont feel comfortable with the change im fine with that.

@BlenderBoi
Copy link
Owner

I think it would be a good addition, I will merge it, but I will take some time to study it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants