Skip to content

Instantly share code, notes, and snippets.

@MarkC-b3d
Last active July 6, 2019 16:02
Show Gist options
  • Save MarkC-b3d/fce522da2ed7d923572e2d37b8932cea to your computer and use it in GitHub Desktop.
Save MarkC-b3d/fce522da2ed7d923572e2d37b8932cea to your computer and use it in GitHub Desktop.
MakeCloth.py generates a cloth sim within blender similar to makepillow.py
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_info = {
"name": "Make Cloth",
"author": "Mark C <BlendedMarks>",
"version": (0,1),
"blender": (2, 79, 0),
"location": "View3D > Spacebar Menu",
"description": "Generates a cloth sim to be used for blankets on couches.",
"warning": "Collision Must Be Set Manually",
"wiki_url": "",
"tracker_url": "",
"category": "Object"}
import bpy
class MakeCloth(bpy.types.Operator):
"""Make Cloth Sims The Easy Way""" # blender will use this as a tooltip for menu items and buttons.
bl_idname = "object.make_cloth" # unique identifier for buttons and menu items to reference.
bl_label = "Make Cloth" # display name in the interface.
bl_options = {'REGISTER', 'UNDO'} # enable undo for the operator.
def execute(self, context): # execute() is called by blender when running the operator.
# The original script
scene = context.scene
#This sets 3D cursor 2 metres (6.5ft) in air
bpy.context.space_data.cursor_location[0] = 0
bpy.context.space_data.cursor_location[1] = 0
bpy.context.space_data.cursor_location[2] = 2#this is the value you change for how high/low the cloth sim is.
bpy.ops.mesh.primitive_plane_add(radius=1, view_align=False, enter_editmode=False, location=(0, 0, 2))
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.subdivide(number_cuts=10, smoothness=0)#subdivides mesh
bpy.ops.object.editmode_toggle()#edit mode escape
bpy.ops.object.modifier_add(type='CLOTH')
bpy.context.object.modifiers["Cloth"].settings.quality = 15
bpy.context.object.modifiers["Cloth"].collision_settings.friction = 30
bpy.context.object.modifiers["Cloth"].collision_settings.use_self_collision = True
bpy.ops.ptcache.bake_all(bake=True)
return {'FINISHED'} # this lets blender know the operator finished successfully.
def register():
bpy.utils.register_class(MakeCloth)
def unregister():
bpy.utils.unregister_class(MakeCloth)
# This allows you to run the script directly from blenders text editor
# to test the addon without having to install it.
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment