Paste Code
Paste Blends
Paste Images
# First import bpy to get access to well... everything in blender
from bpy import *
import bpy
import math, mathutils, random

class GMP_Panel(bpy.types.Panel):
bl_label = "Generative Modeling"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
#bl_context = "object"

def draw(self, context):
layout = self.layout

scn = bpy.context.scene

row = layout.row()
#row = row.column()

row = row.column()
row.label(text="Body parameter")

row = row.column()
row.prop( scn, "Body_Len" )
row = row.column()
row.prop( scn, "Body_Phase" )
row = row.column()
row.prop( scn, "Body_Step" )
row = row.column()
row.prop( scn, "Body_Amplitude" )
row = row.column()
row.prop( scn, "Body_StepAngle" )
row = row.column()
row.prop( scn, "Body_ModAmplitude" )
row = row.column()
row.prop( scn, "Body_ModStep" )

row = row.column()
row.label(text="Arm parameter")

row = row.column()
row.prop( scn, "Arm_Len" )
row = row.column()
row.prop( scn, "Arm_Phase" )
row = row.column()
row.prop( scn, "Arm_Step" )
row = row.column()
row.prop( scn, "Arm_Amplitude" )
row = row.column()
row.prop( scn, "Arm_StepAngle" )
row = row.column()
row.prop( scn, "Arm_ModAmplitude" )
row = row.column()
row.prop( scn, "Arm_ModStep" )
row = row.column()
row.prop( scn, "Arm_Joint" )

row = row.column()
row.label(text="Leg parameter")

row = row.column()
row.prop( scn, "Leg_Len" )
row = row.column()
row.prop( scn, "Leg_Phase" )
row = row.column()
row.prop( scn, "Leg_Step" )
row = row.column()
row.prop( scn, "Leg_Amplitude" )
row = row.column()
row.prop( scn, "Leg_StepAngle" )
row = row.column()
row.prop( scn, "Leg_ModAmplitude" )
row = row.column()
row.prop( scn, "Leg_ModStep" )
row = row.column()
row.prop( scn, "Leg_Joint" )

row = row.column()
row.label(text="Horn parameter")

row = row.column()
row.prop( scn, "Horn_Len" )
row = row.column()
row.prop( scn, "Horn_Phase" )
row = row.column()
row.prop( scn, "Horn_Step" )
row = row.column()
row.prop( scn, "Horn_Amplitude" )
row = row.column()
row.prop( scn, "Horn_StepAngle" )
row = row.column()
row.prop( scn, "Horn_ModAmplitude" )
row = row.column()
row.prop( scn, "Horn_ModStep" )
row = row.column()
row.prop( scn, "Horn_Joint" )

row = row.column()
row.label(text=" ")

row.operator( "bpt.generate_op" )

class GMP_Operator(bpy.types.Operator):
bl_idname = "bpt.generate_op"
bl_label = "Generate"

def execute(self, context):
Body_Len = bpy.context.scene.Body_Len
Body_Phase = bpy.context.scene.Body_Phase
Body_Step = bpy.context.scene.Body_Step
Body_Amplitude = bpy.context.scene.Body_Amplitude
Body_StepAngle = bpy.context.scene.Body_StepAngle
Body_ModAmplitude = bpy.context.scene.Body_ModAmplitude
Body_ModStep = bpy.context.scene.Body_ModStep
Body_Joint = 0

Arm_Len = bpy.context.scene.Arm_Len
Arm_Phase = bpy.context.scene.Arm_Phase
Arm_Step = bpy.context.scene.Arm_Step
Arm_Amplitude = bpy.context.scene.Arm_Amplitude
Arm_StepAngle = bpy.context.scene.Arm_StepAngle
Arm_ModAmplitude = bpy.context.scene.Arm_ModAmplitude
Arm_ModStep = bpy.context.scene.Arm_ModStep
Arm_Joint = bpy.context.scene.Arm_Joint

Leg_Len = bpy.context.scene.Leg_Len
Leg_Phase = bpy.context.scene.Leg_Phase
Leg_Step = bpy.context.scene.Leg_Step
Leg_Amplitude = bpy.context.scene.Leg_Amplitude
Leg_StepAngle = bpy.context.scene.Leg_StepAngle
Leg_ModAmplitude = bpy.context.scene.Leg_ModAmplitude
Leg_ModStep = bpy.context.scene.Leg_ModStep
Leg_Joint = bpy.context.scene.Leg_Joint

Horn_Len = bpy.context.scene.Horn_Len
Horn_Phase = bpy.context.scene.Horn_Phase
Horn_Step = bpy.context.scene.Horn_Step
Horn_Amplitude = bpy.context.scene.Horn_Amplitude
Horn_StepAngle = bpy.context.scene.Horn_StepAngle
Horn_ModAmplitude = bpy.context.scene.Horn_ModAmplitude
Horn_ModStep = bpy.context.scene.Horn_ModStep
Horn_Joint = bpy.context.scene.Horn_Joint

for CP in range(Body_Phase, Body_Phase+180, 36):
for CS in range(Body_Step, Body_Step+20, 4):
generate(Body_Len, CP, CS, Body_Amplitude, Body_StepAngle, Body_ModAmplitude, Body_ModStep, Body_Joint, Arm_Len, Arm_Phase, Arm_Step, Arm_Amplitude, Arm_StepAngle, Arm_ModAmplitude, Arm_ModStep, Arm_Joint, Leg_Len, Leg_Phase, Leg_Step, Leg_Amplitude, Leg_StepAngle, Leg_ModAmplitude, Leg_ModStep, Leg_Joint, Horn_Len, Horn_Phase, Horn_Step, Horn_Amplitude, Horn_StepAngle, Horn_ModAmplitude, Horn_ModStep, Horn_Joint )
paramText(Body_Len, CP, CS, Body_Amplitude, Body_StepAngle, Body_ModAmplitude, Body_ModStep, Body_Joint, Arm_Len, Arm_Phase, Arm_Step, Arm_Amplitude, Arm_StepAngle, Arm_ModAmplitude, Arm_ModStep, Arm_Joint, Leg_Len, Leg_Phase, Leg_Step, Leg_Amplitude, Leg_StepAngle, Leg_ModAmplitude, Leg_ModStep, Leg_Joint, Horn_Len, Horn_Phase, Horn_Step, Horn_Amplitude, Horn_StepAngle, Horn_ModAmplitude, Horn_ModStep, Horn_Joint )

self.report( "INFO", "New Life was Generated!" )
return {'FINISHED'}

def register():
bpy.utils.register_class( GMP_Operator )
bpy.utils.register_class( GMP_Panel )

def unregister():
bpy.utils.register_class( GMP_Operator )
bpy.utils.register_class( GMP_Panel )

def paramText(Body_Len, CP, CS, Body_Amplitude, Body_StepAngle, Body_ModAmplitude, Body_ModStep, Body_Joint, Arm_Len, Arm_Phase, Arm_Step, Arm_Amplitude, Arm_StepAngle, Arm_ModAmplitude, Arm_ModStep, Arm_Joint, Leg_Len, Leg_Phase, Leg_Step, Leg_Amplitude, Leg_StepAngle, Leg_ModAmplitude, Leg_ModStep, Leg_Joint, Horn_Len, Horn_Phase, Horn_Step, Horn_Amplitude, Horn_StepAngle, Horn_ModAmplitude, Horn_ModStep, Horn_Joint ):
bpy.ops.object.text_add(view_align=False, enter_editmode=False, location=((CP-180)/5, CS*2, 0), rotation=(0, 0, 0), layers=(False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False))
bpy.ops.transform.rotate(value=(-1.5708,), axis=(-1, -2.22045e-16, -0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)

bpy.ops.object.editmode_toggle()
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')

bpy.ops.font.text_insert(text=str(Body_Len), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(CP), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(CS), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Body_Amplitude), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Body_StepAngle), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Body_ModAmplitude), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Body_ModStep), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Body_Joint), accent=False)
bpy.ops.font.line_break(ctrl=False)

bpy.ops.font.text_insert(text=str(Arm_Len), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Arm_Phase), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Arm_Step), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Arm_Amplitude), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Arm_StepAngle), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Arm_ModAmplitude), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Arm_ModStep), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Arm_Joint), accent=False)
bpy.ops.font.line_break(ctrl=False)

bpy.ops.font.text_insert(text=str(Leg_Len), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Leg_Phase), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Leg_Step), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Leg_Amplitude), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Leg_StepAngle), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Leg_ModAmplitude), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Leg_ModStep), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Leg_Joint), accent=False)
bpy.ops.font.line_break(ctrl=False)

bpy.ops.font.text_insert(text=str(Horn_Len), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Horn_Phase), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Horn_Step), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Horn_Amplitude), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Horn_StepAngle), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Horn_ModAmplitude), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Horn_ModStep), accent=False)
bpy.ops.font.line_break(ctrl=False)
bpy.ops.font.text_insert(text=str(Horn_Joint), accent=False)
bpy.ops.font.line_break(ctrl=False)

bpy.ops.object.editmode_toggle()
bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)

def generate(body_Len, body_Phase, body_Step, body_Amplitude, body_StepAngle, body_ModAmplitude, body_ModStep, body_Joint, arm_Len, arm_Phase, arm_Step, arm_Amplitude, arm_StepAngle, arm_ModAmplitude, arm_ModStep, arm_Joint, leg_Len, leg_Phase, leg_Step, leg_Amplitude, leg_StepAngle, leg_ModAmplitude, leg_ModStep, leg_Joint, horn_Len, horn_Phase, horn_Step, horn_Amplitude, horn_StepAngle, horn_ModAmplitude, horn_ModStep, horn_Joint ):

# Extrude One Step ---------------------------------------->
def transStep(dA, sA, rA, axis_x, axis_y, axis_z):
bpy.ops.transform.shrink_fatten(value=dA, mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
bpy.ops.transform.resize(value=(sA, sA, sA), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)

# Get the mesh
me = ob.data
# Loop through the faces to find the center
for f in me.faces:
if f.select == True:
center = f.center
if center[0] > 0.0:
rotDir = 1.0
else:
rotDir = -1.0

bpy.ops.transform.rotate(value=(rA*rotDir,), axis=(axis_x, axis_y, axis_z), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)

# TransformFaces(Multi Step) ------------------------------------------------------->
def transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startDeg, stepDeg, modLevel, modRate, axis, jointNum):
# Make sure nothing is selected
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')

# Select the vertex group
selPart(vGroup)

# Go into object mode so that we are sure we have the current list of faces
bpy.ops.object.mode_set(mode='OBJECT')

# Make a nice list to keep the vertex groups in
groupList = []

# Now loop through all the faces
for i, f in enumerate(ob.data.faces):

# If this face is selected~
if ob.data.faces[i].select == True:

# Create a new vertex group!
newGroup = ob.vertex_groups.new('mygroup')
groupList.append(newGroup)

# Get all the vertices in the current face and add them to the new group
for v in f.vertices:
newGroup.add([v], 1.0, 'REPLACE')

# Now we loop through the groups and do what we want.
for g in groupList:

# Make sure nothing is selected
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')

# Make the group in our list the active one
ob.vertex_groups.active_index = g.index

# Select all the verts in the active group
bpy.ops.object.vertex_group_select()

bpy.ops.object.vertex_group_remove(all=False)

# AND NOW WE CAN DO OUR STUFF... little test example follows
t = startDeg
oldRatio = 1.0
# Shape
j = 0
for i in range(stepNum):

bpy.ops.mesh.extrude(type='REGION')

# An added trick... remove the extruded face from all vertex groups after the first extrusion (i == 0)
# This way it can't get extruded again
# Because the edge of the first face can be part of multiple groups
if not i:
bpy.ops.object.vertex_group_remove_from(all=True)

bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')

#newRatio = mainLevel*(math.sin(math.radians(t))+2.0)/oldRatio
newRatio = mainLevel*(math.sin(math.radians(t)+(math.sin(math.radians(t/2.3))))+2.0)/oldRatio

dA = stepDist
sA = newRatio
rA = modLevel*math.sin(math.radians(t*modRate))*(-stepRot/10)
axis_x = axis[0]
axis_y = axis[1]
axis_z = axis[2]
transStep(dA, sA, rA, axis_x, axis_y, axis_z)
if jointNum != 0:
j = j+1
if j == jointNum:
bpy.ops.mesh.extrude(type='REGION')
transStep(-0.01, 0.6, 0, axis_x, axis_y, axis_z)
bpy.ops.mesh.extrude(type='REGION')
transStep(-0.01, 1.66, 0, axis_x, axis_y, axis_z)
j = 0
t = t + stepDeg*2
oldRatio = oldRatio*newRatio

# transformFaces!(END) --------------------------------------------------<

# bodyShape ------------------------------------------------------>
def bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startDeg, stepDeg, modLevel, modRate, axis, jointNum):
newGroup = ob.vertex_groups.new(vGroup)
bpy.ops.object.mode_set(mode='OBJECT')

# Lets loop through all the faces in the mesh
for f in ob.data.faces:

# See if the current face's centre is above 0.0 on the Z axis
if f.center[1] > -0.1:
# Set select to true
f.select = True
else:
f.select = False

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_assign(new=False)

transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startDeg, stepDeg, modLevel, modRate, axis, jointNum)
bpy.ops.mesh.select_all(action='DESELECT')
# bodyShape(END) ---------------------------------------------------<

# select faces from Groups --------------------------------------------->
def selPart(vGroup):
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_select()
bpy.ops.object.vertex_group_remove(all=False)
# select faces from Groups (END)----------------------------------------<

# cell subdivide --------------------------------------------->
def cellSubdiv():
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
# cell subdivide (END)----------------------------------------<

# assignFaces ----------------------------------------------->
def assignFaces(vGroup, xMin, xMax, yMin, yMax, zMin, zMax):
newGroup = ob.vertex_groups.new(vGroup)
bpy.ops.object.mode_set(mode='OBJECT')

for f in ob.data.faces:

if f.center[0] > xMin and f.center[0] < xMax and f.center[1] > yMin and f.center[1] < yMax and f.center[2] > zMin and f.center[2] < zMax:
f.select = True
else:
f.select = False

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_assign(new=False)
bpy.ops.mesh.select_all(action='DESELECT')
# assignFaces (END)------------------------------------------<

# assignFacesAngle--------------------------------------------->
def assignFacesAngle(vGroup, fAngleMin, fAngleMax, yMin, yMax):
newGroup = ob.vertex_groups.new(vGroup)
bpy.ops.object.mode_set(mode='OBJECT')

up = mathutils.Vector((0.0,0.0,1.0))

# Lets loop through all the faces in the mesh
for f in ob.data.faces:
# If the angle between up and the face's normal (direction) is smaller than 45...
# The face must be pointing up
# To compare the angle we need 45 degrees in radians, not in degrees!
# Math with angles is usually all in radians
if f.normal.angle(up) > math.radians(fAngleMin) and f.normal.angle(up) < math.radians(fAngleMax) and f.center[1] > yMin and f.center[1] < yMax :
# Set select to true
f.select = True
else:
f.select = False

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_assign(new=False)
bpy.ops.mesh.select_all(action='DESELECT')
# assignFacesAngle(END)--------------------------------------<

# Set Up Parameters --------------------------------------->
#bMainLevel = 3
#bStepAngle = 30
#bModLevel = 3.0
#bModRate = 10.0

#pMainLevel = 0.3
#pStepAngle = 1.0
#pModLevel = 1.0
#pModRate = 5.0

#sAngle = startDeg
#sRot = stepDeg
# Set Up Parameter(END) -----------------------------------<

# Generate Object ----------------------------------------->
# -- Set Up(START) ------------------------------------------>
#bpy.ops.object.delete()

bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=((body_Phase-180)/5, body_Step*2, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.transform.rotate(value=(-1.5708,), axis=(-1, -2.22045e-16, -4.93038e-32), constraint_axis=(False, False, False), constraint_orientation='LOCAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
bpy.ops.transform.resize(value=(0.05, 1, 0.05), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)
bpy.ops.object.mode_set(mode='OBJECT')

# Now we want to get the active object
# To do this we go through bpy.context... because that is basicly "what you are working on right now"
# bpy.data could work too, but then you'd need to do more work to find your current active object
ob = bpy.context.active_object

# A new trick... lets go into edit mode and deselect everything ('SELECT' works too)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')

# Get the screen areas we are working in right now
areas = bpy.context.screen.areas

# Loop through all the areas
for area in areas:

# See if the current area is a 3D view
if area.type == 'VIEW_3D':

# Set the pivot point to individual origins
area.active_space.pivot_point = 'INDIVIDUAL_ORIGINS'

# -- Set Up(END) ------------------------------------------<


# bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axisArray, jointNum)
bodyShape('body', body_Amplitude, body_Len, -0.5, body_StepAngle, body_Phase, body_Step, body_ModAmplitude, body_ModStep, [-1, -2.22045e-16, -0], 0)
#bodyShape('body', 3, 12, -0.5, 0, 5, 30, 3, 10, [-1, -2.22045e-16, -0])
bpy.ops.object.mode_set(mode='OBJECT')

cellSubdiv()
# spine
#transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis)
#assignFaces('spine', -5.0, 5.0, 2.5, 20.0, 0.0, 10.0)
#transformFaces('spine', 0.3, 10, -0.2, -0.5, sAngle, 10, 5, 20, [-2.22045e-16, -1, -0])
assignFacesAngle('arm', 0, 45, 2.5, 20.0)
assignFacesAngle('horn', 0, 45, 0.5, 1.5)
assignFacesAngle('leg', 135, 180, 2.0, 4.0)

transformFaces('arm', arm_Amplitude, arm_Len, -0.2, arm_Step, arm_Phase, arm_StepAngle, arm_ModAmplitude, arm_ModStep, [-2.22045e-16, -1, -0], arm_Joint)
transformFaces('horn', horn_Amplitude, horn_Len, -0.1,horn_Step, horn_Phase, horn_StepAngle, horn_ModAmplitude, horn_ModStep, [-2.22045e-16, -1, -0], horn_Joint)
transformFaces('leg', leg_Amplitude, leg_Len, -0.2, leg_Step, leg_Phase, leg_StepAngle, leg_ModAmplitude, leg_ModStep, [-2.22045e-16, -1, -0], leg_Joint)

bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.mode_set(mode='OBJECT')

#fileName = '/Users/shige/Documents/BlenderPJ/GMP_model3/A_Life_'+str(sRot)+'_'+str(sAngle)
#fileName = '/Users/shige/Documents/BlenderPJ/GMP_model/A_Life_sRot_-10_10_2_sAngle_0_180_15)'

# Save the current file! (with a specific fileName)
# bpy.ops.wm.save_as_mainfile(filepath=fileName, check_existing=False, compress=True)

#bpy.ops.object.delete()

if __name__ == '__main__':
bpy.types.Scene.Body_Len = bpy.props.IntProperty(name="Body_Len", default = 12, min = 5, max = 20, description = "Body Len")
bpy.types.Scene.Body_Phase = bpy.props.IntProperty(name="Body_Phase", default = 0, min = -180, max = 180, description = "Body Phase")
bpy.types.Scene.Body_Step = bpy.props.IntProperty(name="Body_Step", default = 0, min = -90, max = 90, description = "Body Step")

bpy.types.Scene.Body_Amplitude = bpy.props.FloatProperty(name="Body_Amplitude", default = 1, min = 1, max = 5, description = "Body Amplitude")
bpy.types.Scene.Body_StepAngle = bpy.props.FloatProperty(name="Body_StepAngle", default = 0, min = -20, max = 20, description = "Body StepAngle")
bpy.types.Scene.Body_ModAmplitude = bpy.props.FloatProperty(name="Body_ModAmplitude", default = 0, min = -3, max = 3, description = "Body ModAmplitude")
bpy.types.Scene.Body_ModStep = bpy.props.FloatProperty(name="Body_ModStep", default = 0, min = -10, max = 10, description = "Body ModStep")

bpy.types.Scene.Arm_Len = bpy.props.IntProperty(name="Arm_Len", default = 10, min = 1, max = 20, description = "Arm Len")
bpy.types.Scene.Arm_Phase = bpy.props.IntProperty(name="Arm_Phase", default = 0, min = -180, max = 180, description = "Arm Phase")
bpy.types.Scene.Arm_Step = bpy.props.IntProperty(name="Arm_Step", default = 0, min = -90, max = 90, description = "Arm Step")

bpy.types.Scene.Arm_Amplitude = bpy.props.FloatProperty(name="Arm_Amplitude", default = 0.3, min = 0.1, max = 1.0, description = "Arm Amplitude")
bpy.types.Scene.Arm_StepAngle = bpy.props.FloatProperty(name="Arm_StepAngle", default = 0, min = -20, max = 20, description = "Arm StepAngle")
bpy.types.Scene.Arm_ModAmplitude = bpy.props.FloatProperty(name="Arm_ModAmplitude", default = 0, min = 0, max = 5, description = "Arm ModAmplitude")
bpy.types.Scene.Arm_ModStep = bpy.props.FloatProperty(name="Arm_ModStep", default = 0, min = 0, max = 20, description = "Arm ModStep")
bpy.types.Scene.Arm_Joint = bpy.props.IntProperty(name="Arm_Joint", default = 0, min = 0, max = 5, description = "Arm Joint")

bpy.types.Scene.Leg_Len = bpy.props.IntProperty(name="Leg_Len", default = 10, min = 1, max = 20, description = "Leg Len")
bpy.types.Scene.Leg_Phase = bpy.props.IntProperty(name="Leg_Phase", default = 0, min = -180, max = 180, description = "Leg Phase")
bpy.types.Scene.Leg_Step = bpy.props.IntProperty(name="Leg_Step", default = 0, min = -90, max = 90, description = "Leg Step")

bpy.types.Scene.Leg_Amplitude = bpy.props.FloatProperty(name="Leg_Amplitude", default = 0.3, min = 0.1, max = 1.0, description = "Leg Amplitude")
bpy.types.Scene.Leg_StepAngle = bpy.props.FloatProperty(name="Leg_StepAngle", default = 0, min = -20, max = 20, description = "Leg StepAngle")
bpy.types.Scene.Leg_ModAmplitude = bpy.props.FloatProperty(name="Leg_ModAmplitude", default = 0, min = 0, max = 5, description = "Leg ModAmplitude")
bpy.types.Scene.Leg_ModStep = bpy.props.FloatProperty(name="Leg_ModStep", default = 0, min = 0, max = 20, description = "Leg ModStep")
bpy.types.Scene.Leg_Joint = bpy.props.IntProperty(name="Leg_Joint", default = 0, min = 0, max = 5, description = "Leg Joint")

bpy.types.Scene.Horn_Len = bpy.props.IntProperty(name="Horn_Len", default = 4, min = 1, max = 20, description = "Horn Len")
bpy.types.Scene.Horn_Phase = bpy.props.IntProperty(name="Horn_Phase", default = 0, min = -180, max = 180, description = "Horn Phase")
bpy.types.Scene.Horn_Step = bpy.props.IntProperty(name="Horn_Step", default = 0, min = -90, max = 90, description = "Horn Step")

bpy.types.Scene.Horn_Amplitude = bpy.props.FloatProperty(name="Horn_Amplitude", default = 0.3, min = 0.1, max = 1.0, description = "Horn Amplitude")
bpy.types.Scene.Horn_StepAngle = bpy.props.FloatProperty(name="Horn_StepAngle", default = 0, min = -20, max = 20, description = "Horn StepAngle")
bpy.types.Scene.Horn_ModAmplitude = bpy.props.FloatProperty(name="Horn_ModAmplitude", default = 0, min = 0, max = 5, description = "Horn ModAmplitude")
bpy.types.Scene.Horn_ModStep = bpy.props.FloatProperty(name="Horn_ModStep", default = 0, min = 0, max = 20, description = "Horn ModStep")
bpy.types.Scene.Horn_Joint = bpy.props.IntProperty(name="Horn_Joint", default = 0, min = 0, max = 5, description = "Horn Joint")

register()
  1. # First import bpy to get access to well... everything in blender
  2. from bpy import *
  3. import bpy
  4. import math, mathutils, random
  5.  
  6. class GMP_Panel(bpy.types.Panel):
  7.         bl_label = "Generative Modeling"
  8.         bl_space_type = "VIEW_3D"
  9.         bl_region_type = "TOOLS"
  10.         #bl_context = "object"
  11.  
  12.         def draw(self, context):
  13.                 layout = self.layout
  14.                
  15.                 scn = bpy.context.scene
  16.                
  17.                 row = layout.row()
  18.                 #row = row.column()
  19.                
  20.                 row = row.column()
  21.                 row.label(text="Body parameter")
  22.                
  23.                 row = row.column()
  24.                 row.prop( scn, "Body_Len" )
  25.                 row = row.column()
  26.                 row.prop( scn, "Body_Phase" )
  27.                 row = row.column()
  28.                 row.prop( scn, "Body_Step" )
  29.                 row = row.column()
  30.                 row.prop( scn, "Body_Amplitude" )
  31.                 row = row.column()
  32.                 row.prop( scn, "Body_StepAngle" )
  33.                 row = row.column()
  34.                 row.prop( scn, "Body_ModAmplitude" )
  35.                 row = row.column()
  36.                 row.prop( scn, "Body_ModStep" )
  37.                
  38.                 row = row.column()
  39.                 row.label(text="Arm parameter")
  40.                
  41.                 row = row.column()
  42.                 row.prop( scn, "Arm_Len" )
  43.                 row = row.column()
  44.                 row.prop( scn, "Arm_Phase" )
  45.                 row = row.column()
  46.                 row.prop( scn, "Arm_Step" )
  47.                 row = row.column()
  48.                 row.prop( scn, "Arm_Amplitude" )
  49.                 row = row.column()
  50.                 row.prop( scn, "Arm_StepAngle" )
  51.                 row = row.column()
  52.                 row.prop( scn, "Arm_ModAmplitude" )
  53.                 row = row.column()
  54.                 row.prop( scn, "Arm_ModStep" )
  55.                 row = row.column()
  56.                 row.prop( scn, "Arm_Joint" )
  57.                
  58.                 row = row.column()
  59.                 row.label(text="Leg parameter")
  60.                
  61.                 row = row.column()
  62.                 row.prop( scn, "Leg_Len" )
  63.                 row = row.column()
  64.                 row.prop( scn, "Leg_Phase" )
  65.                 row = row.column()
  66.                 row.prop( scn, "Leg_Step" )
  67.                 row = row.column()
  68.                 row.prop( scn, "Leg_Amplitude" )
  69.                 row = row.column()
  70.                 row.prop( scn, "Leg_StepAngle" )
  71.                 row = row.column()
  72.                 row.prop( scn, "Leg_ModAmplitude" )
  73.                 row = row.column()
  74.                 row.prop( scn, "Leg_ModStep" )
  75.                 row = row.column()
  76.                 row.prop( scn, "Leg_Joint" )
  77.                
  78.                 row = row.column()
  79.                 row.label(text="Horn parameter")
  80.                
  81.                 row = row.column()
  82.                 row.prop( scn, "Horn_Len" )
  83.                 row = row.column()
  84.                 row.prop( scn, "Horn_Phase" )
  85.                 row = row.column()
  86.                 row.prop( scn, "Horn_Step" )
  87.                 row = row.column()
  88.                 row.prop( scn, "Horn_Amplitude" )
  89.                 row = row.column()
  90.                 row.prop( scn, "Horn_StepAngle" )
  91.                 row = row.column()
  92.                 row.prop( scn, "Horn_ModAmplitude" )
  93.                 row = row.column()
  94.                 row.prop( scn, "Horn_ModStep" )
  95.                 row = row.column()
  96.                 row.prop( scn, "Horn_Joint" )
  97.                
  98.                 row = row.column()
  99.                 row.label(text=" ")
  100.                
  101.                 row.operator( "bpt.generate_op" )
  102.                
  103. class GMP_Operator(bpy.types.Operator):
  104.         bl_idname = "bpt.generate_op"
  105.         bl_label = "Generate"
  106.  
  107.         def execute(self, context):
  108.                 Body_Len = bpy.context.scene.Body_Len
  109.                 Body_Phase = bpy.context.scene.Body_Phase
  110.                 Body_Step = bpy.context.scene.Body_Step
  111.                 Body_Amplitude = bpy.context.scene.Body_Amplitude
  112.                 Body_StepAngle = bpy.context.scene.Body_StepAngle
  113.                 Body_ModAmplitude = bpy.context.scene.Body_ModAmplitude
  114.                 Body_ModStep = bpy.context.scene.Body_ModStep
  115.                 Body_Joint = 0
  116.                
  117.                 Arm_Len = bpy.context.scene.Arm_Len
  118.                 Arm_Phase = bpy.context.scene.Arm_Phase
  119.                 Arm_Step = bpy.context.scene.Arm_Step
  120.                 Arm_Amplitude = bpy.context.scene.Arm_Amplitude
  121.                 Arm_StepAngle = bpy.context.scene.Arm_StepAngle
  122.                 Arm_ModAmplitude = bpy.context.scene.Arm_ModAmplitude
  123.                 Arm_ModStep = bpy.context.scene.Arm_ModStep
  124.                 Arm_Joint = bpy.context.scene.Arm_Joint
  125.                
  126.                 Leg_Len = bpy.context.scene.Leg_Len
  127.                 Leg_Phase = bpy.context.scene.Leg_Phase
  128.                 Leg_Step = bpy.context.scene.Leg_Step
  129.                 Leg_Amplitude = bpy.context.scene.Leg_Amplitude
  130.                 Leg_StepAngle = bpy.context.scene.Leg_StepAngle
  131.                 Leg_ModAmplitude = bpy.context.scene.Leg_ModAmplitude
  132.                 Leg_ModStep = bpy.context.scene.Leg_ModStep
  133.                 Leg_Joint = bpy.context.scene.Leg_Joint
  134.                
  135.                 Horn_Len = bpy.context.scene.Horn_Len
  136.                 Horn_Phase = bpy.context.scene.Horn_Phase
  137.                 Horn_Step = bpy.context.scene.Horn_Step
  138.                 Horn_Amplitude = bpy.context.scene.Horn_Amplitude
  139.                 Horn_StepAngle = bpy.context.scene.Horn_StepAngle
  140.                 Horn_ModAmplitude = bpy.context.scene.Horn_ModAmplitude
  141.                 Horn_ModStep = bpy.context.scene.Horn_ModStep
  142.                 Horn_Joint = bpy.context.scene.Horn_Joint
  143.                
  144.                 for CP in range(Body_Phase, Body_Phase+180, 36):
  145.                         for CS in range(Body_Step, Body_Step+20, 4):
  146.                                 generate(Body_Len, CP, CS, Body_Amplitude, Body_StepAngle, Body_ModAmplitude, Body_ModStep, Body_Joint, Arm_Len, Arm_Phase, Arm_Step, Arm_Amplitude, Arm_StepAngle, Arm_ModAmplitude, Arm_ModStep, Arm_Joint, Leg_Len, Leg_Phase, Leg_Step, Leg_Amplitude, Leg_StepAngle, Leg_ModAmplitude, Leg_ModStep, Leg_Joint, Horn_Len, Horn_Phase, Horn_Step, Horn_Amplitude, Horn_StepAngle, Horn_ModAmplitude, Horn_ModStep, Horn_Joint )
  147.                                 paramText(Body_Len, CP, CS, Body_Amplitude, Body_StepAngle, Body_ModAmplitude, Body_ModStep, Body_Joint, Arm_Len, Arm_Phase, Arm_Step, Arm_Amplitude, Arm_StepAngle, Arm_ModAmplitude, Arm_ModStep, Arm_Joint, Leg_Len, Leg_Phase, Leg_Step, Leg_Amplitude, Leg_StepAngle, Leg_ModAmplitude, Leg_ModStep, Leg_Joint, Horn_Len, Horn_Phase, Horn_Step, Horn_Amplitude, Horn_StepAngle, Horn_ModAmplitude, Horn_ModStep, Horn_Joint )
  148.                                
  149.                 self.report( "INFO", "New Life was Generated!" )
  150.                 return {'FINISHED'}
  151.  
  152. def register():
  153.         bpy.utils.register_class( GMP_Operator )
  154.         bpy.utils.register_class( GMP_Panel )
  155.  
  156. def unregister():
  157.         bpy.utils.register_class( GMP_Operator )
  158.         bpy.utils.register_class( GMP_Panel )
  159.  
  160. def paramText(Body_Len, CP, CS, Body_Amplitude, Body_StepAngle, Body_ModAmplitude, Body_ModStep, Body_Joint, Arm_Len, Arm_Phase, Arm_Step, Arm_Amplitude, Arm_StepAngle, Arm_ModAmplitude, Arm_ModStep, Arm_Joint, Leg_Len, Leg_Phase, Leg_Step, Leg_Amplitude, Leg_StepAngle, Leg_ModAmplitude, Leg_ModStep, Leg_Joint, Horn_Len, Horn_Phase, Horn_Step, Horn_Amplitude, Horn_StepAngle, Horn_ModAmplitude, Horn_ModStep, Horn_Joint ):
  161.         bpy.ops.object.text_add(view_align=False, enter_editmode=False, location=((CP-180)/5, CS*2, 0), rotation=(0, 0, 0), layers=(False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False))
  162.         bpy.ops.transform.rotate(value=(-1.5708,), axis=(-1, -2.22045e-16, -0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
  163.  
  164.         bpy.ops.object.editmode_toggle()
  165.         bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
  166.         bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
  167.         bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
  168.         bpy.ops.font.delete(type='PREVIOUS_OR_SELECTION')
  169.  
  170.         bpy.ops.font.text_insert(text=str(Body_Len), accent=False)
  171.         bpy.ops.font.line_break(ctrl=False)
  172.         bpy.ops.font.text_insert(text=str(CP), accent=False)
  173.         bpy.ops.font.line_break(ctrl=False)
  174.         bpy.ops.font.text_insert(text=str(CS), accent=False)
  175.         bpy.ops.font.line_break(ctrl=False)
  176.         bpy.ops.font.text_insert(text=str(Body_Amplitude), accent=False)
  177.         bpy.ops.font.line_break(ctrl=False)
  178.         bpy.ops.font.text_insert(text=str(Body_StepAngle), accent=False)
  179.         bpy.ops.font.line_break(ctrl=False)
  180.         bpy.ops.font.text_insert(text=str(Body_ModAmplitude), accent=False)
  181.         bpy.ops.font.line_break(ctrl=False)
  182.         bpy.ops.font.text_insert(text=str(Body_ModStep), accent=False)
  183.         bpy.ops.font.line_break(ctrl=False)
  184.         bpy.ops.font.text_insert(text=str(Body_Joint), accent=False)
  185.         bpy.ops.font.line_break(ctrl=False)
  186.        
  187.         bpy.ops.font.text_insert(text=str(Arm_Len), accent=False)
  188.         bpy.ops.font.line_break(ctrl=False)
  189.         bpy.ops.font.text_insert(text=str(Arm_Phase), accent=False)
  190.         bpy.ops.font.line_break(ctrl=False)
  191.         bpy.ops.font.text_insert(text=str(Arm_Step), accent=False)
  192.         bpy.ops.font.line_break(ctrl=False)
  193.         bpy.ops.font.text_insert(text=str(Arm_Amplitude), accent=False)
  194.         bpy.ops.font.line_break(ctrl=False)
  195.         bpy.ops.font.text_insert(text=str(Arm_StepAngle), accent=False)
  196.         bpy.ops.font.line_break(ctrl=False)
  197.         bpy.ops.font.text_insert(text=str(Arm_ModAmplitude), accent=False)
  198.         bpy.ops.font.line_break(ctrl=False)
  199.         bpy.ops.font.text_insert(text=str(Arm_ModStep), accent=False)
  200.         bpy.ops.font.line_break(ctrl=False)
  201.         bpy.ops.font.text_insert(text=str(Arm_Joint), accent=False)
  202.         bpy.ops.font.line_break(ctrl=False)
  203.        
  204.         bpy.ops.font.text_insert(text=str(Leg_Len), accent=False)
  205.         bpy.ops.font.line_break(ctrl=False)
  206.         bpy.ops.font.text_insert(text=str(Leg_Phase), accent=False)
  207.         bpy.ops.font.line_break(ctrl=False)
  208.         bpy.ops.font.text_insert(text=str(Leg_Step), accent=False)
  209.         bpy.ops.font.line_break(ctrl=False)
  210.         bpy.ops.font.text_insert(text=str(Leg_Amplitude), accent=False)
  211.         bpy.ops.font.line_break(ctrl=False)
  212.         bpy.ops.font.text_insert(text=str(Leg_StepAngle), accent=False)
  213.         bpy.ops.font.line_break(ctrl=False)
  214.         bpy.ops.font.text_insert(text=str(Leg_ModAmplitude), accent=False)
  215.         bpy.ops.font.line_break(ctrl=False)
  216.         bpy.ops.font.text_insert(text=str(Leg_ModStep), accent=False)
  217.         bpy.ops.font.line_break(ctrl=False)
  218.         bpy.ops.font.text_insert(text=str(Leg_Joint), accent=False)
  219.         bpy.ops.font.line_break(ctrl=False)
  220.        
  221.         bpy.ops.font.text_insert(text=str(Horn_Len), accent=False)
  222.         bpy.ops.font.line_break(ctrl=False)
  223.         bpy.ops.font.text_insert(text=str(Horn_Phase), accent=False)
  224.         bpy.ops.font.line_break(ctrl=False)
  225.         bpy.ops.font.text_insert(text=str(Horn_Step), accent=False)
  226.         bpy.ops.font.line_break(ctrl=False)
  227.         bpy.ops.font.text_insert(text=str(Horn_Amplitude), accent=False)
  228.         bpy.ops.font.line_break(ctrl=False)
  229.         bpy.ops.font.text_insert(text=str(Horn_StepAngle), accent=False)
  230.         bpy.ops.font.line_break(ctrl=False)
  231.         bpy.ops.font.text_insert(text=str(Horn_ModAmplitude), accent=False)
  232.         bpy.ops.font.line_break(ctrl=False)
  233.         bpy.ops.font.text_insert(text=str(Horn_ModStep), accent=False)
  234.         bpy.ops.font.line_break(ctrl=False)
  235.         bpy.ops.font.text_insert(text=str(Horn_Joint), accent=False)
  236.         bpy.ops.font.line_break(ctrl=False)
  237.        
  238.         bpy.ops.object.editmode_toggle()
  239.         bpy.ops.transform.resize(value=(0.1, 0.1, 0.1), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)
  240.  
  241. def generate(body_Len, body_Phase, body_Step, body_Amplitude, body_StepAngle, body_ModAmplitude, body_ModStep, body_Joint, arm_Len, arm_Phase, arm_Step, arm_Amplitude, arm_StepAngle, arm_ModAmplitude, arm_ModStep, arm_Joint, leg_Len, leg_Phase, leg_Step, leg_Amplitude, leg_StepAngle, leg_ModAmplitude, leg_ModStep, leg_Joint, horn_Len, horn_Phase, horn_Step, horn_Amplitude, horn_StepAngle, horn_ModAmplitude, horn_ModStep, horn_Joint ):
  242.  
  243.         # Extrude One Step ---------------------------------------->
  244.         def transStep(dA, sA, rA, axis_x, axis_y, axis_z):
  245.                 bpy.ops.transform.shrink_fatten(value=dA, mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
  246.                 bpy.ops.transform.resize(value=(sA, sA, sA), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)
  247.        
  248.                 # Get the mesh
  249.                 me = ob.data
  250.                 # Loop through the faces to find the center
  251.                 for f in me.faces:
  252.                         if f.select == True:
  253.                                 center = f.center
  254.                 if center[0] > 0.0:
  255.                         rotDir = 1.0
  256.                 else:
  257.                         rotDir = -1.0
  258.        
  259.                 bpy.ops.transform.rotate(value=(rA*rotDir,), axis=(axis_x, axis_y, axis_z), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
  260.        
  261.         # TransformFaces(Multi Step) ------------------------------------------------------->
  262.         def transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startDeg, stepDeg, modLevel, modRate, axis, jointNum):
  263.                 # Make sure nothing is selected
  264.                 bpy.ops.object.mode_set(mode='EDIT')
  265.                 bpy.ops.mesh.select_all(action='DESELECT')
  266.        
  267.                 # Select the vertex group
  268.                 selPart(vGroup)
  269.        
  270.                 # Go into object mode so that we are sure we have the current list of faces
  271.                 bpy.ops.object.mode_set(mode='OBJECT')
  272.  
  273.                 # Make a nice list to keep the vertex groups in
  274.                 groupList = []
  275.  
  276.                 # Now loop through all the faces
  277.                 for i, f in enumerate(ob.data.faces):
  278.                
  279.                         # If this face is selected~
  280.                         if ob.data.faces[i].select == True:
  281.  
  282.                                 # Create a new vertex group!
  283.                                 newGroup = ob.vertex_groups.new('mygroup')
  284.                                 groupList.append(newGroup)
  285.  
  286.                                 # Get all the vertices in the current face and add them to the new group
  287.                                 for v in f.vertices:
  288.                                         newGroup.add([v], 1.0, 'REPLACE')
  289.                        
  290.                 # Now we loop through the groups and do what we want.
  291.                 for g in groupList:
  292.  
  293.                         # Make sure nothing is selected
  294.                         bpy.ops.object.mode_set(mode='EDIT')
  295.                         bpy.ops.mesh.select_all(action='DESELECT')
  296.  
  297.                         # Make the group in our list the active one
  298.                         ob.vertex_groups.active_index = g.index
  299.  
  300.                         # Select all the verts in the active group
  301.                         bpy.ops.object.vertex_group_select()
  302.  
  303.                         bpy.ops.object.vertex_group_remove(all=False)
  304.  
  305.                         # AND NOW WE CAN DO OUR STUFF... little test example follows
  306.                         t = startDeg
  307.                         oldRatio = 1.0
  308.                         # Shape
  309.                         j = 0
  310.                         for i in range(stepNum):
  311.      
  312.                                 bpy.ops.mesh.extrude(type='REGION')
  313.                        
  314.                                 # An added trick... remove the extruded face from all vertex groups after the first extrusion (i == 0)
  315.                                 # This way it can't get extruded again
  316.                                 # Because the edge of the first face can be part of multiple groups
  317.                                 if not i:
  318.                                         bpy.ops.object.vertex_group_remove_from(all=True)
  319.                        
  320.                                 bpy.ops.object.mode_set(mode='OBJECT')
  321.                                 bpy.ops.object.mode_set(mode='EDIT')
  322.                        
  323.                                 #newRatio = mainLevel*(math.sin(math.radians(t))+2.0)/oldRatio
  324.                                 newRatio = mainLevel*(math.sin(math.radians(t)+(math.sin(math.radians(t/2.3))))+2.0)/oldRatio
  325.                                
  326.                                 dA = stepDist
  327.                                 sA = newRatio
  328.                                 rA = modLevel*math.sin(math.radians(t*modRate))*(-stepRot/10)
  329.                                 axis_x = axis[0]
  330.                                 axis_y = axis[1]
  331.                                 axis_z = axis[2]
  332.                                 transStep(dA, sA, rA, axis_x, axis_y, axis_z)
  333.                                 if jointNum != 0:
  334.                                         j = j+1
  335.                                         if j == jointNum:
  336.                                                 bpy.ops.mesh.extrude(type='REGION')
  337.                                                 transStep(-0.01, 0.6, 0, axis_x, axis_y, axis_z)
  338.                                                 bpy.ops.mesh.extrude(type='REGION')
  339.                                                 transStep(-0.01, 1.66, 0, axis_x, axis_y, axis_z)
  340.                                                 j = 0
  341.                                 t = t + stepDeg*2
  342.                                 oldRatio = oldRatio*newRatio
  343.        
  344.         # transformFaces!(END) --------------------------------------------------<
  345.  
  346.         # bodyShape ------------------------------------------------------>
  347.         def bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startDeg, stepDeg, modLevel, modRate, axis, jointNum):
  348.                 newGroup = ob.vertex_groups.new(vGroup)
  349.                 bpy.ops.object.mode_set(mode='OBJECT')
  350.        
  351.                 # Lets loop through all the faces in the mesh
  352.                 for f in ob.data.faces:
  353.        
  354.                         # See if the current face's centre is above 0.0 on the Z axis
  355.                         if f.center[1] > -0.1:
  356.                                 # Set select to true
  357.                                 f.select = True
  358.                         else:
  359.                                 f.select = False
  360.                
  361.                 bpy.ops.object.mode_set(mode='EDIT')                   
  362.                 bpy.ops.object.vertex_group_set_active(group=vGroup)
  363.                 bpy.ops.object.vertex_group_assign(new=False)
  364.                
  365.                 transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startDeg, stepDeg, modLevel, modRate, axis, jointNum)
  366.                 bpy.ops.mesh.select_all(action='DESELECT')
  367.         # bodyShape(END) ---------------------------------------------------<
  368.  
  369.         # select faces from Groups --------------------------------------------->
  370.         def selPart(vGroup):
  371.                 bpy.ops.object.vertex_group_set_active(group=vGroup)
  372.                 bpy.ops.object.vertex_group_select()
  373.                 bpy.ops.object.vertex_group_remove(all=False)
  374.         # select faces from Groups (END)----------------------------------------<
  375.        
  376.         # cell subdivide --------------------------------------------->
  377.         def cellSubdiv():
  378.                 bpy.ops.object.modifier_add(type='SUBSURF')
  379.                 bpy.ops.object.mode_set(mode='OBJECT')
  380.                 bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
  381.         # cell subdivide (END)----------------------------------------<
  382.  
  383.         # assignFaces ----------------------------------------------->
  384.         def assignFaces(vGroup, xMin, xMax, yMin, yMax, zMin, zMax):
  385.                 newGroup = ob.vertex_groups.new(vGroup)
  386.                 bpy.ops.object.mode_set(mode='OBJECT')
  387.        
  388.                 for f in ob.data.faces:
  389.                
  390.                         if f.center[0] > xMin and f.center[0] < xMax and f.center[1] > yMin and f.center[1] < yMax and f.center[2] > zMin and f.center[2] < zMax:
  391.                                 f.select = True
  392.                         else:
  393.                                 f.select = False       
  394.                                        
  395.                 bpy.ops.object.mode_set(mode='EDIT')                   
  396.                 bpy.ops.object.vertex_group_set_active(group=vGroup)
  397.                 bpy.ops.object.vertex_group_assign(new=False)
  398.                 bpy.ops.mesh.select_all(action='DESELECT')
  399.         # assignFaces (END)------------------------------------------<
  400.  
  401.         # assignFacesAngle--------------------------------------------->
  402.         def assignFacesAngle(vGroup, fAngleMin, fAngleMax, yMin, yMax):
  403.                 newGroup = ob.vertex_groups.new(vGroup)
  404.                 bpy.ops.object.mode_set(mode='OBJECT')
  405.        
  406.                 up = mathutils.Vector((0.0,0.0,1.0))
  407.  
  408.                 # Lets loop through all the faces in the mesh
  409.                 for f in ob.data.faces:
  410.                         # If the angle between up and the face's normal (direction) is smaller than 45...
  411.                         # The face must be pointing up
  412.                         # To compare the angle we need 45 degrees in radians, not in degrees!
  413.                         # Math with angles is usually all in radians
  414.                         if f.normal.angle(up) > math.radians(fAngleMin) and f.normal.angle(up) < math.radians(fAngleMax) and f.center[1] > yMin and f.center[1] < yMax :
  415.                                 # Set select to true
  416.                                 f.select = True
  417.                         else:
  418.                                 f.select = False
  419.                        
  420.                 bpy.ops.object.mode_set(mode='EDIT')                   
  421.                 bpy.ops.object.vertex_group_set_active(group=vGroup)
  422.                 bpy.ops.object.vertex_group_assign(new=False)
  423.                 bpy.ops.mesh.select_all(action='DESELECT')
  424.         # assignFacesAngle(END)--------------------------------------<
  425.  
  426.         # Set Up Parameters     --------------------------------------->
  427.         #bMainLevel = 3
  428.         #bStepAngle = 30
  429.         #bModLevel = 3.0
  430.         #bModRate =     10.0
  431.  
  432.         #pMainLevel = 0.3
  433.         #pStepAngle = 1.0
  434.         #pModLevel = 1.0
  435.         #pModRate = 5.0
  436.  
  437.         #sAngle = startDeg
  438.         #sRot = stepDeg
  439.         # Set Up Parameter(END) -----------------------------------<
  440.  
  441.         # Generate Object ----------------------------------------->
  442.         # -- Set Up(START) ------------------------------------------>
  443.         #bpy.ops.object.delete()
  444.          
  445.         bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=((body_Phase-180)/5, body_Step*2, 0), rotation=(0, 0, 0), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
  446.         bpy.ops.object.mode_set(mode='EDIT')
  447.         bpy.ops.transform.rotate(value=(-1.5708,), axis=(-1, -2.22045e-16, -4.93038e-32), constraint_axis=(False, False, False), constraint_orientation='LOCAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=1, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
  448.         bpy.ops.transform.resize(value=(0.05, 1, 0.05), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', mirror=False, proportional='DISABLED', proportional_edit_falloff='SMOOTH', proportional_size=0.0762767, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), texture_space=False, release_confirm=False)
  449.         bpy.ops.object.mode_set(mode='OBJECT')
  450.  
  451.         # Now we want to get the active object
  452.         # To do this we go through bpy.context... because that is basicly "what you are working on right now"
  453.         # bpy.data could work too, but then you'd need to do more work to find your current active object
  454.         ob = bpy.context.active_object
  455.        
  456.         # A new trick... lets go into edit mode and deselect everything ('SELECT' works too)
  457.         bpy.ops.object.mode_set(mode='EDIT')
  458.         bpy.ops.mesh.select_all(action='DESELECT')
  459.  
  460.         # Get the screen areas we are working in right now
  461.         areas = bpy.context.screen.areas
  462.  
  463.         # Loop through all the areas
  464.         for area in areas:
  465.  
  466.                 # See if the current area is a 3D view
  467.                 if area.type == 'VIEW_3D':
  468.  
  469.                         # Set the pivot point to individual origins
  470.                         area.active_space.pivot_point = 'INDIVIDUAL_ORIGINS'
  471.  
  472.         # -- Set Up(END) ------------------------------------------<
  473.  
  474.        
  475.         # bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axisArray, jointNum)
  476.         bodyShape('body', body_Amplitude, body_Len, -0.5, body_StepAngle, body_Phase, body_Step, body_ModAmplitude, body_ModStep, [-1, -2.22045e-16, -0], 0)
  477.         #bodyShape('body', 3, 12, -0.5, 0, 5, 30, 3, 10, [-1, -2.22045e-16, -0])
  478.         bpy.ops.object.mode_set(mode='OBJECT')
  479.        
  480.         cellSubdiv()
  481.         # spine
  482.         #transformFaces(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis)
  483.         #assignFaces('spine', -5.0, 5.0, 2.5, 20.0, 0.0, 10.0)
  484.         #transformFaces('spine', 0.3, 10, -0.2, -0.5, sAngle, 10, 5, 20, [-2.22045e-16, -1, -0])
  485.         assignFacesAngle('arm', 0, 45, 2.5, 20.0)
  486.         assignFacesAngle('horn', 0, 45, 0.5, 1.5)
  487.         assignFacesAngle('leg', 135, 180, 2.0, 4.0)
  488.        
  489.         transformFaces('arm', arm_Amplitude, arm_Len, -0.2, arm_Step, arm_Phase, arm_StepAngle, arm_ModAmplitude, arm_ModStep, [-2.22045e-16, -1, -0], arm_Joint)
  490.         transformFaces('horn', horn_Amplitude, horn_Len, -0.1,horn_Step, horn_Phase, horn_StepAngle, horn_ModAmplitude, horn_ModStep, [-2.22045e-16, -1, -0], horn_Joint)
  491.         transformFaces('leg', leg_Amplitude, leg_Len, -0.2, leg_Step, leg_Phase, leg_StepAngle, leg_ModAmplitude, leg_ModStep, [-2.22045e-16, -1, -0], leg_Joint)
  492.        
  493.         bpy.ops.object.modifier_add(type='SUBSURF')
  494.         bpy.ops.object.modifier_add(type='SUBSURF')
  495.         bpy.ops.object.mode_set(mode='OBJECT')
  496.        
  497.         #fileName = '/Users/shige/Documents/BlenderPJ/GMP_model3/A_Life_'+str(sRot)+'_'+str(sAngle)
  498.         #fileName = '/Users/shige/Documents/BlenderPJ/GMP_model/A_Life_sRot_-10_10_2_sAngle_0_180_15)'
  499.  
  500.         # Save the current file! (with a specific fileName)            
  501.         # bpy.ops.wm.save_as_mainfile(filepath=fileName, check_existing=False, compress=True)
  502.        
  503.         #bpy.ops.object.delete()
  504.  
  505. if __name__ == '__main__':
  506.         bpy.types.Scene.Body_Len = bpy.props.IntProperty(name="Body_Len", default = 12, min = 5, max = 20, description = "Body Len")
  507.         bpy.types.Scene.Body_Phase = bpy.props.IntProperty(name="Body_Phase", default = 0, min = -180, max = 180, description = "Body Phase")
  508.         bpy.types.Scene.Body_Step = bpy.props.IntProperty(name="Body_Step", default = 0, min = -90, max = 90, description = "Body Step")
  509.        
  510.         bpy.types.Scene.Body_Amplitude = bpy.props.FloatProperty(name="Body_Amplitude", default = 1, min = 1, max = 5, description = "Body Amplitude")
  511.         bpy.types.Scene.Body_StepAngle = bpy.props.FloatProperty(name="Body_StepAngle", default = 0, min = -20, max = 20, description = "Body StepAngle")
  512.         bpy.types.Scene.Body_ModAmplitude = bpy.props.FloatProperty(name="Body_ModAmplitude", default = 0, min = -3, max = 3, description = "Body ModAmplitude")
  513.         bpy.types.Scene.Body_ModStep = bpy.props.FloatProperty(name="Body_ModStep", default = 0, min = -10, max = 10, description = "Body ModStep")
  514.        
  515.         bpy.types.Scene.Arm_Len = bpy.props.IntProperty(name="Arm_Len", default = 10, min = 1, max = 20, description = "Arm Len")
  516.         bpy.types.Scene.Arm_Phase = bpy.props.IntProperty(name="Arm_Phase", default = 0, min = -180, max = 180, description = "Arm Phase")
  517.         bpy.types.Scene.Arm_Step = bpy.props.IntProperty(name="Arm_Step", default = 0, min = -90, max = 90, description = "Arm Step")
  518.  
  519.         bpy.types.Scene.Arm_Amplitude = bpy.props.FloatProperty(name="Arm_Amplitude", default = 0.3, min = 0.1, max = 1.0, description = "Arm Amplitude")
  520.         bpy.types.Scene.Arm_StepAngle = bpy.props.FloatProperty(name="Arm_StepAngle", default = 0, min = -20, max = 20, description = "Arm StepAngle")
  521.         bpy.types.Scene.Arm_ModAmplitude = bpy.props.FloatProperty(name="Arm_ModAmplitude", default = 0, min = 0, max = 5, description = "Arm ModAmplitude")
  522.         bpy.types.Scene.Arm_ModStep = bpy.props.FloatProperty(name="Arm_ModStep", default = 0, min = 0, max = 20, description = "Arm ModStep")
  523.         bpy.types.Scene.Arm_Joint = bpy.props.IntProperty(name="Arm_Joint", default = 0, min = 0, max = 5, description = "Arm Joint")
  524.  
  525.         bpy.types.Scene.Leg_Len = bpy.props.IntProperty(name="Leg_Len", default = 10, min = 1, max = 20, description = "Leg Len")
  526.         bpy.types.Scene.Leg_Phase = bpy.props.IntProperty(name="Leg_Phase", default = 0, min = -180, max = 180, description = "Leg Phase")
  527.         bpy.types.Scene.Leg_Step = bpy.props.IntProperty(name="Leg_Step", default = 0, min = -90, max = 90, description = "Leg Step")
  528.  
  529.         bpy.types.Scene.Leg_Amplitude = bpy.props.FloatProperty(name="Leg_Amplitude", default = 0.3, min = 0.1, max = 1.0, description = "Leg Amplitude")
  530.         bpy.types.Scene.Leg_StepAngle = bpy.props.FloatProperty(name="Leg_StepAngle", default = 0, min = -20, max = 20, description = "Leg StepAngle")
  531.         bpy.types.Scene.Leg_ModAmplitude = bpy.props.FloatProperty(name="Leg_ModAmplitude", default = 0, min = 0, max = 5, description = "Leg ModAmplitude")
  532.         bpy.types.Scene.Leg_ModStep = bpy.props.FloatProperty(name="Leg_ModStep", default = 0, min = 0, max = 20, description = "Leg ModStep")
  533.         bpy.types.Scene.Leg_Joint = bpy.props.IntProperty(name="Leg_Joint", default = 0, min = 0, max = 5, description = "Leg Joint")
  534.        
  535.         bpy.types.Scene.Horn_Len = bpy.props.IntProperty(name="Horn_Len", default = 4, min = 1, max = 20, description = "Horn Len")
  536.         bpy.types.Scene.Horn_Phase = bpy.props.IntProperty(name="Horn_Phase", default = 0, min = -180, max = 180, description = "Horn Phase")
  537.         bpy.types.Scene.Horn_Step = bpy.props.IntProperty(name="Horn_Step", default = 0, min = -90, max = 90, description = "Horn Step")
  538.  
  539.         bpy.types.Scene.Horn_Amplitude = bpy.props.FloatProperty(name="Horn_Amplitude", default = 0.3, min = 0.1, max = 1.0, description = "Horn Amplitude")
  540.         bpy.types.Scene.Horn_StepAngle = bpy.props.FloatProperty(name="Horn_StepAngle", default = 0, min = -20, max = 20, description = "Horn StepAngle")
  541.         bpy.types.Scene.Horn_ModAmplitude = bpy.props.FloatProperty(name="Horn_ModAmplitude", default = 0, min = 0, max = 5, description = "Horn ModAmplitude")
  542.         bpy.types.Scene.Horn_ModStep = bpy.props.FloatProperty(name="Horn_ModStep", default = 0, min = 0, max = 20, description = "Horn ModStep")
  543.         bpy.types.Scene.Horn_Joint = bpy.props.IntProperty(name="Horn_Joint", default = 0, min = 0, max = 5, description = "Horn Joint")
  544.  
  545.         register()
  546.  
go to heaven