Conch Deformer 2.78a

this was a beautiful accident.

#2.78a
#Scale Vertices To Cube
import bpy
import bmesh
from mathutils import Vector

def scale_to_cube(obj, ForceMDist=1.0):
    # Ensure we're in edit mode
    bpy.ops.object.mode_set(mode='EDIT');

    # Get a BMesh from the active object
    bm = bmesh.from_edit_mesh(obj.data);

    # Get the selected vertices
    verts = [v for v in bm.verts if v.select];

    if verts:
        # Calculate the center of the selected vertices
        center = sum((v.co for v in verts), Vector()) / len(verts);

        # Calculate the maximum distance from the center to a vertex
        max_dist = max((v.co - center).length for v in verts);

        # Scale each vertex to form a cube
        for v in verts:
            dist = (v.co - center).length;
            if dist > 0:  # Avoid division by zero
                # Calculate the scaling factor based on distance
                scale_factor = (1 - (dist / max_dist)) ** ForceMDist;
                # Scale the vertex towards the center
                v.co = center + (v.co - center) * scale_factor;

        # Update the mesh
        bmesh.update_edit_mesh(obj.data, True);

# Get the active object
active_obj = bpy.context.object

# Scale the selected vertices to a cube
scale_to_cube(active_obj, 0.15)  # Adjust ForceMDist as needed

but basically it allows you to take a sphere object and deform it into a conch (tweak it only slightly for best results)

tell me does it work in game mode or is it a script for the viewing window? :thinking:

designed for the editor however (untested as Iā€™m less familiar with the newer API) it should work in the UPBGE during runtime. I may need to tweak it slightly for the UPBGE versoin (if I do that) unsure yet.

thank you for your answer - if you make a version for the game engine, post it in this topic, I think many people will be interested to see and test your script :wink:

1 Like