GPencil: Scripting weight_get cannot retrieve weights of certain vertex groups #96799

Closed
opened 2022-03-26 13:25:48 +01:00 by Keny Chatain · 13 comments

System Information
Operating system: Kubuntu 21.04
Graphics card: AMD Radeon Vega 6 Graphics

Blender Version
Broken: 3.2.0.Alpha (branch: master, commit hash : 6bf51ab03a, commit date: Fri, 25 Mar 2022 9:33 PM)

Short description of error

When points of a stroke belong to just one vertex group and the index of that vertex group is not zero, Python API weight_get cannot retrieve weight assigned to points.

Not resolved after #91511.

Exact steps for others to reproduce the error

Run script in attached .blend file (bug.blend).

  • Draw two strokes.
  • Create two vertex groups.
  • Assign all points in first stroke to first vertex group group.
  • Assign all points in second stroke to second vertex group.
  • Call to stroke.points.weight_get(0, 0) results in -1.0
  • Call to stroke.points.weight_get(1, 0) throws Groups: index out of range

It seems that the code in rna_GPencilStrokePoints_weight_get interprets vertex_group_index in two different ways: index in dw array MDeformVert and index of vertex group in object. It checks bounds wrt totweight but gives weights associated. I have a fix ; I'll see if I can figure out how to attach it here.

**System Information** Operating system: Kubuntu 21.04 Graphics card: AMD Radeon Vega 6 Graphics **Blender Version** Broken: 3.2.0.Alpha (branch: master, commit hash : 6bf51ab03a066f8cf37a061ceb8d5c12bd6ea88d, commit date: Fri, 25 Mar 2022 9:33 PM) **Short description of error** When points of a stroke belong to just one vertex group and the index of that vertex group is not zero, Python API `weight_get` cannot retrieve weight assigned to points. Not resolved after [#91511](https://developer.blender.org/T91511). **Exact steps for others to reproduce the error** Run script in attached .blend file ([bug.blend](https://archive.blender.org/developer/F12948172/bug.blend)). - Draw two strokes. - Create two vertex groups. - Assign all points in first stroke to first vertex group group. - Assign all points in second stroke to second vertex group. - Call to `stroke.points.weight_get(0, 0)` results in -1.0 - Call to `stroke.points.weight_get(1, 0)` throws `Groups: index out of range` It seems that the code in `rna_GPencilStrokePoints_weight_get` interprets `vertex_group_index` in two different ways: index in `dw` array `MDeformVert` and index of vertex group in object. It checks bounds wrt `totweight` but gives weights associated. I have a fix ; I'll see if I can figure out how to attach it here.
Author

Added subscriber: @KenyC

Added subscriber: @KenyC
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123

Added subscriber: @antoniov

Added subscriber: @antoniov

Changed status from 'Confirmed' to: 'Needs User Info'

Changed status from 'Confirmed' to: 'Needs User Info'

I cannot reproduce. I guess you are mixing things in your script. I have done a test file to verify the weight API.

image.png

BugWeightAPI.blend

This blend file has a stroke with two vertex group. The first vertex group has assigned a weight of 1.0 to all points. The second vertex group has a 0.5 value for all points. Running the script you get this:

image.png

I cannot reproduce. I guess you are mixing things in your script. I have done a test file to verify the weight API. ![image.png](https://archive.blender.org/developer/F12953615/image.png) [BugWeightAPI.blend](https://archive.blender.org/developer/F12953617/BugWeightAPI.blend) This blend file has a stroke with two vertex group. The first vertex group has assigned a weight of `1.0` to all points. The second vertex group has a `0.5` value for all points. Running the script you get this: ![image.png](https://archive.blender.org/developer/F12953619/image.png)

Changed status from 'Needs User Info' to: 'Confirmed'

Changed status from 'Needs User Info' to: 'Confirmed'
Antonio Vazquez self-assigned this 2022-03-29 11:14:20 +02:00

I looked again and I was testing the wrong thing.

I looked again and I was testing the wrong thing.
Author

Indeed, the problem does not arise when there is just one stroke. Looking at the code, the one stroke vs. two strokes difference makes sense. As I understand it, weight_get checks bounds on vertex_group_index wrt totweight, which is the total number of vertex groups associated with the stroke, not the object.

Indeed, the problem does not arise when there is just one stroke. Looking at the code, the one stroke vs. two strokes difference makes sense. As I understand it, `weight_get` checks bounds on `vertex_group_index` wrt `totweight`, which is the total number of vertex groups associated with the *stroke*, not the *object*.

In #96799#1331389, @KenyC wrote:
Indeed, the problem does not arise when there is just one stroke. Looking at the code, the one stroke vs. two strokes difference makes sense. As I understand it, weight_get checks bounds on vertex_group_index wrt totweight, which is the total number of vertex groups associated with the stroke, not the object.

Yes, this is the problem... Fixing it!

> In #96799#1331389, @KenyC wrote: > Indeed, the problem does not arise when there is just one stroke. Looking at the code, the one stroke vs. two strokes difference makes sense. As I understand it, `weight_get` checks bounds on `vertex_group_index` wrt `totweight`, which is the total number of vertex groups associated with the *stroke*, not the *object*. Yes, this is the problem... Fixing it!

This issue was referenced by 343fc38b8d

This issue was referenced by 343fc38b8d646735f42c88dd9de8a33feaf3cb7f

This issue was referenced by 9450057b43

This issue was referenced by 9450057b43cb278e6b8003f54ec0705dae599165

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#96799
No description provided.