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+40, 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
oldValue = 1.0
#stepDeg = 30
# 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
newValue = (math.sin(math.radians(t)+math.sin(math.radians(t/2.3)))+2.0)*mainLevel
newRatio = newValue/oldValue

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
oldValue = newValue

# 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', 45, 70, 4, 20.0)
assignFacesAngle('horn', 0, 45, 0.5, 1)
assignFacesAngle('leg', 135, 160, 5.0, 20.0)

transformFaces('arm', arm_Amplitude, arm_Len, -0.2, arm_StepAngle, arm_Phase, arm_Step, arm_ModAmplitude, arm_ModStep, [-2.22045e-16, -1, -0], arm_Joint)
transformFaces('horn', horn_Amplitude, horn_Len, -0.2,horn_StepAngle, horn_Phase, horn_Step, horn_ModAmplitude, horn_ModStep, [-2.22045e-16, -1, -0], horn_Joint)
transformFaces('leg', leg_Amplitude, leg_Len, -0.2, leg_StepAngle, leg_Phase, leg_Step, 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')
bpy.ops.object.shade_smooth()

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