From 35a370a41285ca88a81204921b5fc5e77ff3b967 Mon Sep 17 00:00:00 2001 From: Joseph HENRY Date: Tue, 31 Mar 2026 17:32:24 +0200 Subject: [PATCH] Map RNA float array properties to mathutils types using subtype RNA properties with subtypes like TRANSLATION, XYZ, EULER, QUATERNION, COLOR, MATRIX are now mapped to the corresponding mathutils types (Vector, Euler, Quaternion, Color, Matrix) instead of list[float]. Also: - Add gpu.types override for 5.1 (uniform_float accepts mathutils types) - Fix README snippet to use assert for active_object None check Co-Authored-By: Claude Opus 4.6 (1M context) --- README.md | 4 ++-- introspect.py | 15 +++++++++++++++ main.py | 4 ++-- overrides/5.1/gpu.types.json | 7 +++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 overrides/5.1/gpu.types.json diff --git a/README.md b/README.md index f177db0..2ac78dc 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ import bpy # Full autocomplete and type checking obj = bpy.context.active_object -if obj is not None: - print(obj.name) +assert obj is not None +obj.location.x = 1.0 # Collection types with proper methods bpy.data.objects.new("Cube", bpy.data.meshes.new("Mesh")) diff --git a/introspect.py b/introspect.py index bc657e2..6ae06bf 100644 --- a/introspect.py +++ b/introspect.py @@ -2138,6 +2138,21 @@ def rna_property_to_type(prop: object) -> str: if array_length == 0 and is_array: # Dynamic-length array — at runtime this is a bpy_prop_array return f"bpy_prop_array[{base}]" + # Fixed-length float arrays with vector/matrix subtypes are mathutils types + subtype: str = getattr(prop, "subtype", "NONE") + if prop_type == "float" and subtype in ( + "TRANSLATION", "DIRECTION", "VELOCITY", "ACCELERATION", + "XYZ", "XYZ_LENGTH", + ): + return "mathutils.Vector" + if prop_type == "float" and subtype == "EULER": + return "mathutils.Euler" + if prop_type == "float" and subtype == "QUATERNION": + return "mathutils.Quaternion" + if prop_type == "float" and subtype in ("COLOR", "COLOR_GAMMA") and array_length == 3: + return "mathutils.Color" + if prop_type == "float" and subtype == "MATRIX": + return "mathutils.Matrix" return f"list[{base}]" return RNA_TYPE_MAP.get(prop_type, prop_type) diff --git a/main.py b/main.py index e8ac04c..f0bc2a0 100644 --- a/main.py +++ b/main.py @@ -186,8 +186,8 @@ pip install "blender-python-stubs>={major_minor},<{next_minor}" import bpy obj = bpy.context.active_object -if obj is not None: - print(obj.name) +assert obj is not None +obj.location.x = 1.0 bpy.data.objects.new("Cube", bpy.data.meshes.new("Mesh")) ``` diff --git a/overrides/5.1/gpu.types.json b/overrides/5.1/gpu.types.json new file mode 100644 index 0000000..cc0037f --- /dev/null +++ b/overrides/5.1/gpu.types.json @@ -0,0 +1,7 @@ +{ + "GPUShader.uniform_float": { + "params": { + "value": "float | int | Sequence[float] | mathutils.Matrix | mathutils.Vector | mathutils.Euler | mathutils.Quaternion | mathutils.Color" + } + } +}