Skip to main content
edited tags
Link
Blunder
  • 14.8k
  • 4
  • 16
  • 37
deleted 78 characters in body
Source Link
import bpy
import bmesh

def merge_vertices_and_uv_stitch():
    # Make sure we're inIn Edit Mode and Vertex Select Modemode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Apply SHIFT+V (Stitch) operation in UV space
    bpy.ops.uv.stitch()

    # Update the mesh again
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_and_uv_stitch()
import bpy
import bmesh

def merge_vertices_preserve_uvs():
    # Make sure we're in Edit Mode and VertexIn Selectedit Modemode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Ensure UV layers are available
    if not bm.loops.layers.uv:
        return

    uv_layer = bm.loops.layers.uv.verify()

    # Store original UV coordinates
    original_uvs = {}
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.select:
                original_uvs[loop.vert.index] = loop[uv_layer].uv.copy()

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Restore original UV coordinates
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.index in original_uvs:
                loop[uv_layer].uv = original_uvs[loop.vert.index]

    # Final update
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_preserve_uvs()
import bpy
import bmesh

def merge_vertices_and_uv_stitch():
    # Make sure we're in Edit Mode and Vertex Select Mode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Apply SHIFT+V (Stitch) operation in UV space
    bpy.ops.uv.stitch()

    # Update the mesh again
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_and_uv_stitch()
import bpy
import bmesh

def merge_vertices_preserve_uvs():
    # Make sure we're in Edit Mode and Vertex Select Mode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Ensure UV layers are available
    if not bm.loops.layers.uv:
        return

    uv_layer = bm.loops.layers.uv.verify()

    # Store original UV coordinates
    original_uvs = {}
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.select:
                original_uvs[loop.vert.index] = loop[uv_layer].uv.copy()

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Restore original UV coordinates
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.index in original_uvs:
                loop[uv_layer].uv = original_uvs[loop.vert.index]

    # Final update
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_preserve_uvs()
import bpy
import bmesh

def merge_vertices_and_uv_stitch():
    # In Edit mode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Apply SHIFT+V (Stitch) operation in UV space
    bpy.ops.uv.stitch()

    # Update the mesh again
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_and_uv_stitch()
import bpy
import bmesh

def merge_vertices_preserve_uvs():
    # In edit mode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Ensure UV layers are available
    if not bm.loops.layers.uv:
        return

    uv_layer = bm.loops.layers.uv.verify()

    # Store original UV coordinates
    original_uvs = {}
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.select:
                original_uvs[loop.vert.index] = loop[uv_layer].uv.copy()

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Restore original UV coordinates
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.index in original_uvs:
                loop[uv_layer].uv = original_uvs[loop.vert.index]

    # Final update
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_preserve_uvs()
added 2230 characters in body
Source Link

I tried simple approaches like:

import bpy
import bmesh

def merge_vertices_and_uv_stitch():
    # Make sure we're in Edit Mode and Vertex Select Mode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Apply SHIFT+V (Stitch) operation in UV space
    bpy.ops.uv.stitch()

    # Update the mesh again
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_and_uv_stitch()

And even more abstract ideas like this which makes things weird:

import bpy
import bmesh

def merge_vertices_preserve_uvs():
    # Make sure we're in Edit Mode and Vertex Select Mode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Ensure UV layers are available
    if not bm.loops.layers.uv:
        return

    uv_layer = bm.loops.layers.uv.verify()

    # Store original UV coordinates
    original_uvs = {}
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.select:
                original_uvs[loop.vert.index] = loop[uv_layer].uv.copy()

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Restore original UV coordinates
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.index in original_uvs:
                loop[uv_layer].uv = original_uvs[loop.vert.index]

    # Final update
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_preserve_uvs()

No luck until now :(

Example of the kind of gap I mean: enter image description here

Example of the kind of gap I mean: enter image description here

I tried simple approaches like:

import bpy
import bmesh

def merge_vertices_and_uv_stitch():
    # Make sure we're in Edit Mode and Vertex Select Mode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Apply SHIFT+V (Stitch) operation in UV space
    bpy.ops.uv.stitch()

    # Update the mesh again
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_and_uv_stitch()

And even more abstract ideas like this which makes things weird:

import bpy
import bmesh

def merge_vertices_preserve_uvs():
    # Make sure we're in Edit Mode and Vertex Select Mode
    bpy.ops.object.mode_set(mode='EDIT')
    bpy.ops.mesh.select_mode(type="VERT")

    # Get the active mesh
    obj = bpy.context.edit_object
    me = obj.data
    bm = bmesh.from_edit_mesh(me)

    # Ensure UV layers are available
    if not bm.loops.layers.uv:
        return

    uv_layer = bm.loops.layers.uv.verify()

    # Store original UV coordinates
    original_uvs = {}
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.select:
                original_uvs[loop.vert.index] = loop[uv_layer].uv.copy()

    # Merge selected vertices at center
    bpy.ops.mesh.merge(type='CENTER')

    # Update the mesh
    bmesh.update_edit_mesh(me)

    # Restore original UV coordinates
    for face in bm.faces:
        for loop in face.loops:
            if loop.vert.index in original_uvs:
                loop[uv_layer].uv = original_uvs[loop.vert.index]

    # Final update
    bmesh.update_edit_mesh(me)

# Run the function
merge_vertices_preserve_uvs()

No luck until now :(

Example of the kind of gap I mean: enter image description here

Source Link
Loading