enenra / space-engineers-utilities

A Blender 4.0+ addon to streamline working on assets for Space Engineers.
https://spaceengineers.wiki.gg/wiki/Modding/Tools/Space_Engineers_Utilities
GNU General Public License v3.0
45 stars 12 forks source link

add problem vertex script to aid with character weighting #379

Closed chipstix213 closed 8 months ago

chipstix213 commented 8 months ago

add this helpful tool as a button, its an advanced thing but you should already be that level to attempt this.

I see it going next to the bone renaming buttons.

script from Stollie here

enenra commented 8 months ago

The code:

import bpy

print("Start script")

me = bpy.context.object.data                                        # the selected mesh
grps = bpy.context.object.vertex_groups                             # all vertex groups in the mesh
grps.new(name="ProblemVertices")                                       # add a vertex group to the mesh
myvertexgroup = grps[-1]                                            # the last vertex group in the mesh - our new group

# optional part which when uncommented deletes vertices 
# from groups where the vertex has weight 0 for that group.
#for vertex in me.vertices:
#    for grpelement in vertex.groups:                                # for each vertex group element in the mesh
#       if grpelement.weight == 0.0:                                # if the vertex is unweighted
#           grps[grpelement.group].remove([vertex.index])           #remove it from that group
#           print("Removed Vertex from group")
#       if len(vertex.groups) == 0:                                    # if the vertex is not a member of any groups
#           myvertexgroup.add([vertex.index], 1.0, 'ADD')           # add it to the last group with weight 1
#           print("Unweighted vertex added to group")

for vertex in me.vertices:                                          # for each vertex
    thisweight = 0.0                                                #keep track of total weight

    for grpelement in vertex.groups:                                # for each vertex group element in the mesh
        thisweight += grpelement.weight

    if thisweight == 0.0:                                             # if the vertex weights don't exceed 0.0
        myvertexgroup.add([vertex.index], 0.0, 'ADD')               # add the vertex to the last group with weight 0.0
        print("Vertex weight 0 found")

print("Finished script")