Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functionality for easily selecting vertices influenced by a target/shapekey #179

Open
unicornlox opened this issue Apr 8, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@unicornlox
Copy link

unicornlox commented Apr 8, 2024

We update vertex groups in areas like face, hand, and foot with shapekeys, but do we have the ability to select vertex groups through these shapekeys?
likethis

@unicornlox unicornlox added the enhancement New feature or request label Apr 8, 2024
@unicornlox
Copy link
Author

Actually, how do you get the coordinates in the statement "vertex_group_information["basemesh"]["scalp"] = [226,...]" in mpfb/entities/socketobject/_extra_vertex_groups.py file, this can also work for me.

@joepal1976
Copy link
Contributor

I haven't been able to find any obvious way to select vertices influenced by a shape key via the UI. It should not be that difficult to write such a utility though. The information about which vertices are influenced by a target (ie a slider under model, not any shape key) is available from the target information.

In general, utility functions for manipulating and reading shape keys are available in https://github.com/makehumancommunity/mpfb2/blob/blender4/src/mpfb/services/targetservice.py

A destructive way to get the coordinates after shape keys is by using the bake_targets method. But you could always make a copy before baking. With a basemesh selected, you can get the coordinate of vertex with index 226 after shape keys by running the following in the scripting tab:

import bpy
from mpfb.services.targetservice import TargetService

selected = bpy.context.active_object

print("Coords of vertex 226 before shape keys: " + str(selected.data.vertices[226].co))

duplicated = selected.copy()
duplicated.data = selected.data.copy()
TargetService.bake_targets(duplicated)

print("Coords of vertex 226 after shape keys: " + str(duplicated.data.vertices[226].co))

bpy.data.objects.remove(duplicated)

Or, in extension, if you want to print all coordinates in the scalp group:

import bpy
from mpfb.services.targetservice import TargetService
from mpfb.entities.socketobject import BASEMESH_EXTRA_GROUPS

selected = bpy.context.active_object

duplicated = selected.copy()
duplicated.data = selected.data.copy()
TargetService.bake_targets(duplicated)

print("Coords in scalp: ")

for index in BASEMESH_EXTRA_GROUPS["scalp"]:
    print("    Coords for vertex " + str(index) + " are " + str(duplicated.data.vertices[index].co))

bpy.data.objects.remove(duplicated)

@joepal1976
Copy link
Contributor

Getting information about a shape key can also be done via TargetService. For example, for the nose-scale-depth-incr shape key:

import bpy
from mpfb.services.targetservice import TargetService

selected = bpy.context.active_object

target_info = TargetService.get_shape_key_as_dict(selected, "nose-scale-depth-incr")
print("The following vertices are influenced by the shape key:")
for vert_info in target_info["vertices"]:
    print(vert_info[0])

@unicornlox
Copy link
Author

@joepal1976 thank you very much for your reply.

@joepal1976 joepal1976 changed the title Getting vertices from a shapekey? Functionality for easily selecting vertices influenced by a target/shapekey May 7, 2024
@joepal1976 joepal1976 self-assigned this May 7, 2024
@joepal1976 joepal1976 added this to the 2.0 beta 1 milestone May 7, 2024
@joepal1976 joepal1976 modified the milestones: 2.0 beta 1, 2.1 beta 1 May 25, 2024
@joepal1976
Copy link
Contributor

This is more complicated than initially thought. Postponing until a later release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants