Skip to content

Commit

Permalink
Merge pull request #143 from DoctorPresto/main
Browse files Browse the repository at this point in the history
fix weight transfer
  • Loading branch information
DoctorPresto authored Apr 22, 2024
2 parents 571261c + d8667d6 commit b5ed6ed
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions i_scene_cp77_gltf/main/meshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def CP77CollectionList(self, context):
items = []
## don't include these as their not useful
excluded_names = ["Collection", "Scene Collection"]
excluded_names = ["Collection", "Scene Collection", "glTF_not_exported"]

for collection in bpy.data.collections:
if collection.name not in excluded_names:
Expand Down Expand Up @@ -140,28 +140,31 @@ def CP77ArmatureSet(self, context):


def trans_weights(self, context):
current_mode = context.mode
props = context.scene.cp77_panel_props
source_mesh_name = props.mesh_source
target_mesh_name = props.mesh_target
active_objs = context.selected_objects
# Get the source collection
source_mesh = bpy.data.collections.get(source_mesh_name)

# Get the target collection
target_mesh = bpy.data.collections.get(target_mesh_name)



if source_mesh and target_mesh:
if current_mode != 'OBJECT':
bpy.ops.object.mode_set(mode='OBJECT')
# Deselect all objects in the scene
bpy.ops.object.select_all(action='DESELECT')

# Iterate through objects in the source collection
# Select the objects in the source collection
for source_obj in source_mesh.objects:
source_obj.select_set(True)

# Set the active object to the last selected source object
bpy.context.view_layer.objects.active = source_obj

# Switch to OBJECT mode
bpy.ops.object.mode_set(mode='OBJECT')

# Iterate through objects in the target collection
for target_obj in target_mesh.objects:
Expand All @@ -175,9 +178,27 @@ def trans_weights(self, context):
layers_select_dst='NAME',
layers_select_src='ALL'
)

# Deselect all objects again
bpy.ops.object.select_all(action='DESELECT')
context.view_layer.objects.active = None

for obj in active_objs:
obj.select_set(True)
context.view_layer.objects.active = obj


if context.mode != current_mode:
try:
bpy.ops.object.mode_set(mode=current_mode)

except TypeError:

if current_mode == 'PAINT_WEIGHT':
bpy.ops.object.mode_set(mode='WEIGHT_PAINT')
elif current_mode == 'EDIT_MESH':
bpy.ops.object.mode_set(mode='EDIT')
elif current_mode == 'PAINT_VERTEX':
bpy.ops.object.mode_set(mode='VERTEX_PAINT')



def CP77UvChecker(self, context):
Expand Down

0 comments on commit b5ed6ed

Please sign in to comment.