Mesh Mangler

Okay, so I spent some time playing around and made myself this.

The script just takes all the vertices of a mesh and moves them around in random directions to give the mesh a bit of a crumpled look. It has a slider to adjust for the severity of the mess you want to make of it. It’s probably good for things like rumpled cloth or crinkled up paper.

I’m not sure I’d call this a replacement for displacement maps but I had fun with it and felt the need to share.

Cheers.

Attachments

mesh_mangler.blend (374 KB)

what a funny little script, well done :slight_smile:

hi, I added code to make this an addon.
it’s just a fun script, you can get subtle results with small changes.
or just hack the mesh to peices if your mad at it… :evilgrin:

bl_info = {
    "name": "Mesh Mangler",
    "author": "Phil Cote",
    "version": (7,),
    "blender": (2, 5, 7),
    "api": 36147,
    "location": "View3d > Toolbar",
    "description": "Mess up the mesh",
    "warning": "",
    "wiki_url": "",
    "tracker_url": "",
    "category": "Mesh"}

"""
Mesh Mangler
by Phil Cote

Description: 
A really simple mesh mangler done just for the pure sake of making weird messed up random looking shapes.

"""

import bpy, random, time
from pdb import set_trace
    
class MeshManglerOperator(bpy.types.Operator):
    '''push vertices on the selected object around in random directions to create a crumpled 
    look.'''
    bl_idname = "bpt.mesh_mangler"
    bl_label = "Mesh Mangler"
    

    @classmethod
    def poll(cls, context):
        ob = context.active_object
        return ob != None and ob.type == 'MESH'

    def execute(self, context):
        mesh = context.active_object.data
        verts, faces = mesh.vertices, mesh.faces
        randomMag = bpy.context.scene.randomMagnitude
   
        random.seed( time.time() )
        
        for vert in verts:
            xVal = .01 * random.randrange( -randomMag, randomMag )
            yVal = .01 * random.randrange( -randomMag, randomMag)
            zVal = .01 * random.randrange( -randomMag, randomMag )
            vert.co.x = vert.co.x + xVal
            vert.co.y = vert.co.y + yVal
            vert.co.z = vert.co.z + zVal    
            
        return {'FINISHED'}


class MeshManglerPanel( bpy.types.Panel ):
    
    bl_label = "Mesh Mangler"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_context = "objectmode"
    
    def draw( self, context ):
        scn = context.scene
        
        layout = self.layout
        col = layout.column()
        col.prop( scn, "randomMagnitude" )
        col.operator( "bpt.mesh_mangler" )
        
    
def register():
    bpy.utils.register_class(MeshManglerOperator)
    bpy.utils.register_class( MeshManglerPanel )
    scnType = bpy.types.Scene
    scnType.randomMagnitude = bpy.props.IntProperty( name = "How Much Mangling", 
                                                 default = 5, min = 1, max = 20, 
                            description = "The (+) and (-) number range for a random number to be picked from" )


def unregister():
    bpy.utils.unregister_class(MeshManglerOperator)
    bpy.utils.unregister_class(MeshManglerPanel)


if __name__ == "__main__":
    register()

enjoy.

Cool. Thanks for making this. :slight_smile:

Recent talk about shape key scripting gave me the idea of doing an animatable version of Mesh Mangler for those wanting to animate weird shifting morphing blobs. Here’s the code for that one. Enjoy :slight_smile:


bl_info = {     "name": "Mesh Mangler",     
"author": "Phil Cote",     
"version": (7,),     
"blender": (2, 5, 7),    
"api": 36147,     
"location": "View3d > Toolbar",    
"description": "Generate shape keys for animating a morphing mess of a mesh",     
"warning": "",     
"wiki_url": "",     
"tracker_url": "",     
"category": "Mesh"}  

"""
Ani-Mangler
by Phil Cote
http://www.blenderpythontutorials.com/scripts.php

DESCRIPTION: 
This script creates shape keys for the selected object and then proceeds to 
take those shape keys and move them around in random directions.
You can then take those keys and animate them as you see fit to create neat 
shape shifting space blob.

LICENSE:
This script is released under the Gnu Public License v. 2.
You may read the text of this license under the "GPL" text block 
that came with this blend file.

HOW TO USE:
1.  Select the mesh you want to create mangled shape keys for.
2.  Set the degree of mangling you want.
3.  Press the "Ani-Mangle" button.
4.  Repeat steps 2 and 3 for each mangled shape key you wish to create.
5.  Keyframe those shape keys to your hearts content.

"""

import bpy, random, time
from pdb import set_trace
    
class MeshManglerOperator(bpy.types.Operator):
    '''push vertices on the selected object around in random directions to create a crumpled 
    look.'''
    bl_idname = "bpt.ani_mangler"
    bl_label = "Ani-Mangle"
    

    @classmethod
    def poll(cls, context):
        ob = context.active_object
        return ob != None and ob.type == 'MESH'

    def execute(self, context):
        
        random.seed( time.time() )
        randomMag = bpy.context.scene.randomMagnitude
        
        ob = context.object
        shapeKey = ob.shape_key_add()
        verts = shapeKey.data
        
        for vert in verts:
            xVal = .01 * random.randrange( -randomMag, randomMag )
            yVal = .01 * random.randrange( -randomMag, randomMag)
            zVal = .01 * random.randrange( -randomMag, randomMag )
            vert.co.x = vert.co.x + xVal
            vert.co.y = vert.co.y + yVal
            vert.co.z = vert.co.z + zVal    
            
        return {'FINISHED'}


class MeshManglerPanel( bpy.types.Panel ):
    
    bl_label = "Animangler"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_context = "objectmode"
    
    def draw( self, context ):
        scn = context.scene
        
        layout = self.layout
        col = layout.column()
        col.prop( scn, "randomMagnitude" )
        col.operator( "bpt.ani_mangler" )
        
    
def register():
    bpy.utils.register_class(MeshManglerOperator)
    bpy.utils.register_class( MeshManglerPanel )
    scnType = bpy.types.Scene
    scnType.randomMagnitude = bpy.props.IntProperty( name = "How Much Mangling", 
                                                 default = 5, min = 1, max = 20, 
                            description = "The (+) and (-) number range for a random number to be picked from" )


def unregister():
    bpy.utils.unregister_class(MeshManglerOperator)
    bpy.utils.unregister_class(MeshManglerPanel)


if __name__ == "__main__":
    register()


And with the Youtube demo, I think I can call this weird distraction done.

Okay, a few quick naming fixes and NOW I’m done having my fun with this.


"""
Ani-Mangler
by Phil Cote

DESCRIPTION: 
This script creates shape keys for the selected object and then proceeds to 
take those shape keys and move them around in random directions.
You can then take those keys and animate them as you see fit to create neat 
shape shifting space blob.

LICENSE:
This script is released under the Gnu Public License v. 2.
You may read the text of this license under the "GPL" text block 
that came with this blend file.  If not available, GPL v2 can be reviewed at http://www.gnu.org/licenses/gpl-2.0.txt

HOW TO USE:
1.  Select the mesh you want to create mangled shape keys for.
2.  Set the degree of mangling you want.
3.  Press the "Ani-Mangle" button.
4.  Repeat steps 2 and 3 for each mangled shape key you wish to create.

"""

import bpy, random, time
from pdb import set_trace
    
class AnimanglerOperator(bpy.types.Operator):
    '''push vertices on the selected object around in random directions to create a crumpled 
    look.'''
    bl_idname = "bpt.ani_mangler"
    bl_label = "Ani-Mangle"
    

    @classmethod
    def poll(cls, context):
        ob = context.active_object
        return ob != None and ob.type == 'MESH'

    def execute(self, context):
        
        random.seed( time.time() )
        randomMag = bpy.context.scene.randomMagnitude
        
        ob = context.object
        shapeKey = ob.shape_key_add()
        verts = shapeKey.data
        
        for vert in verts:
            xVal = .01 * random.randrange( -randomMag, randomMag )
            yVal = .01 * random.randrange( -randomMag, randomMag)
            zVal = .01 * random.randrange( -randomMag, randomMag )
            vert.co.x = vert.co.x + xVal
            vert.co.y = vert.co.y + yVal
            vert.co.z = vert.co.z + zVal    
            
        return {'FINISHED'}


class AnimanglerPanel( bpy.types.Panel ):
    
    bl_label = "Animangler"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_context = "objectmode"
    
    def draw( self, context ):
        scn = context.scene
        
        layout = self.layout
        col = layout.column()
        col.prop( scn, "randomMagnitude" )
        col.operator( "bpt.ani_mangler" )
        
    
def register():
    bpy.utils.register_class(AnimanglerOperator)
    bpy.utils.register_class( AnimanglerPanel )
    scnType = bpy.types.Scene
    scnType.randomMagnitude = bpy.props.IntProperty( name = "How Much Mangling", 
                                                 default = 5, min = 1, max = 20, 
                            description = "The (+) and (-) number range for a random number to be picked from" )


def unregister():
    bpy.utils.unregister_class(AnimanglerOperator)
    bpy.utils.unregister_class(AnimanglerPanel)


if __name__ == "__main__":
    register()

Thanx coter :wink:
Very useful!