nutti / fake-bpy-module

Fake Blender Python API module collection for the code completion.
MIT License
1.38k stars 97 forks source link

Fields that should be Color, Quaternion etc are all rendered as Vector. #126

Closed angavrilov closed 1 year ago

angavrilov commented 1 year ago

It is necessary to find a way to distinguish fields of different mathutils vector variants, which are currently all represented as Vector.

It seems the difference is not reflected in official API documentation, but it is of course known to Blender itself through the subtype property of RNA metadata:

>>> bpy.types.ThemeView3D.bl_rna.properties['wire'].subtype  # Color
'COLOR_GAMMA' 

>>> bpy.types.Object.bl_rna.properties['color'].subtype  # bpy_prop_array
'COLOR'

>>> bpy.types.Object.bl_rna.properties['rotation_quaternion'].subtype  # Quaternion
'QUATERNION' 

>>> bpy.types.Object.bl_rna.properties['rotation_euler'].subtype  # Euler
'EULER'

>>> bpy.types.Object.bl_rna.properties['rotation_axis_angle'].subtype  # bpy_prop_array
'AXISANGLE'

>>> bpy.types.Object.bl_rna.properties['location'].subtype  # Vector
'TRANSLATION'

>>> bpy.types.Object.bl_rna.properties['scale'].subtype  # Vector
'XYZ'

The exact rules from code in bpy_rna.c are:

nutti commented 1 year ago

@angavrilov

It seems the difference is not reflected in official API documentation, but it is of course known to Blender itself through the subtype property of RNA metadata:

As you may know, fake-bpy-module depends heavily on the official document. (You can see the generation script.) The generation script parses the docs and output the modules. https://github.com/nutti/fake-bpy-module/tree/master/src So, changing the official document itself is easier.

But if you have an idea to get the information from Blender itself including all other information, you can rewrite the analyzer instead of the original one. You can fix the generation script of the official document. https://github.com/blender/blender/blob/master/doc/python_api/sphinx_doc_gen.py

BTW, can these type be changed to bpy_prop_array? I think using bpy_prop_array is much easier than parsing RNA metadata.

angavrilov commented 1 year ago

I submitted a patch to add this to the documentation: https://developer.blender.org/D16626

The point of using the correct type is type checking math expressions: obj1.location + obj1.rotation_quaternion @ obj2.location etc is valid.

nutti commented 1 year ago

Thanks. I think changing the official document seems better to me. If the patch is merged, I will close this issue.

angavrilov commented 1 year ago

Well, it probably will require some changes in the code recognising type descriptions. The patch basically changes the standard "float array of ..." descriptions to "mathutils.Vector of ..." or "mathutils.Quaternion rotation of ..." etc, preserving the ranges, default values and so on.

nutti commented 1 year ago

@angavrilov

You patch is now merged :) I will revise the parse algorithm later.

nutti commented 1 year ago

The parse algorithm is fixed now. Thanks for your contribution to the official docs @angavrilov .

angavrilov commented 1 year ago

What about Matrix? The manual now names it explicitly too.

nutti commented 1 year ago

@angavrilov

Thanks. I forgot about Matrix. I have committed the patch.