Page MenuHome

Added function to update many vertex-weights at once
Needs ReviewPublic

Authored by Erik Abrahamsson (erik85) on Mon, Nov 11, 9:11 PM.

Details

Summary

The addon Tissue is using VertexGroup.add heavily for different operations and because it can only update one vertex weight at a time it gets quite slow in Python. This is a try to resolve that by adding a function (add_array) that takes a float array of weights instead of a single weight. My initial tests shows an increase in speed by around a multiple of 8.

Diff Detail

Repository
rB Blender

Event Timeline

I'm not familiar with this area of code, but that won't stop me from wading in with (probably) dumb comments. LOL

First, would consider calling this something more descriptive, like rna_VertexGroup_vertex_add_array()

It is calling (the existing) ED_vgroup_vert_add() in a loop, while I would considering calling a new function you create in object_vgroup.c instead, like "ED_vgroup_vert_add_array()". That way some things that are done per-object or per-deform group can be done only once and the loop can just be of ED_vgroup_nr_vert_add(), since object, deform group, and assignmde all remain the same.

These are the sort of commits that we really need to accelerate python.

so one can use a tree structure to get vertex to effect - and a command to manipulate those vertex / faces / whatever / and apply them in a threaded manner.

Near = kd.find_range(point,radius)
equation = "vertColor", ("lerp",color, (tuple[2] - radius) )
object.data.MeshStroke(Near,equation)

Near = kd.find_range(point,radius)
equation = "vertXYZ", ("lerp", meshVert[tuple[1]].co + (meshVert[tuple[1]].normal*strength), (tuple[2] - radius) )
object.data.MeshStroke(Near,equation)

(some sort of API to pass what to do to multiple vertex / loops/faces in C using py)

hi, I think this type patch would be very useful, not only for Tissue addon. Thanks.
@Campbell Barton (campbellbarton) would you mind adding this to your list?

Thanks Erik! There is an existing Task for that, together with a similar feature for reading the vertex weight all at once:
https://developer.blender.org/T71390

Both features would be really useful!

Thanks Erik! There is an existing Task for that, together with a similar feature for reading the vertex weight all at once:
https://developer.blender.org/T71390
Both features would be really useful!

Ah, ok. Yes I tried a bit today to make a function for reading all weights but failed miserably.. As I said I'm not much of a programmer and these pointers and arrays are confusing me. I will fix this writing function now and then maybe someone could help me with the reading part...

Erik Abrahamsson (erik85) edited the summary of this revision. (Show Details)

Changed name of the function and added a check that the arrays are the same size.

They are small things, but the code formatting is one thing you will probably need to think about. I would run make format with the files you've changed as arguments, that should standardize the formatting.

And for comments, they should start with a capital letter and end with a period generally. You also don't need to split them over multiple lines unless they're over 100 chars long.

I don't know much about the details of this area, but this looks good to me. I do like the idea of having more stuff from Tissue in main Blender.