Monday, May 30, 2011

Record the parameters.

The 'first' try of this project is almost satisfied me, but one problem is 'How to record the parameters for each object'. And I thought this method, adding the text object and write the parameters in it. The code is here.


<CODE>

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)

</CODE>

I ordered some object to 3D print factory, so I have to think the idea for showing them well.

Friday, May 27, 2011

Brush up and New idea.

I did some brushing up the parameters and numeric formula. But I'm thinking about how to do the control of arm length, leg length, and horn length. It's easy to put the slider, but maybe it is too many parameters to set up. I'll think more.



And I add a new idea for shape, it's 'Joint' parameter. This makes joints on arm, leg, and horn. The parameter number means 'make a joint on each steps', not 'numbers of  joints'.


Now the time to make Objects for 3D print. Of course, I'll shape up the code more and more, and make other type code too.

Oh, this code is here

Wednesday, May 25, 2011

Solved! and need more brush up!

The problem of code was solved, and now I could generate with pushing 'Generate' button. But the shape of objects are not satisfied me. I need to brush up the adjusting  the parameters and numeric formula.


Thanks all for helping and cheering me, I'm very appreciate. 

Very close to the answer, but not yet.

Search the sample code and many tries, Now I'm very close to the answer.


But, I got some troubles too. I put the generating code to a Function, and call it from button 'execute' function, I got an error. Upper pic was in case of putting outside of the function.

<CODE>
bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(0, 0, 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
</CODE>

I got an error about 'ob'. What's wrong? /(T-T)\

Monday, May 23, 2011

One step, and stop. Hmmm.

With Kewl's help, I succeeded to show Label on TOOLS. But, I couldn't show button = operator. Hmmm, it's a difficult.



Sunday, May 22, 2011

Next, Go, Next.

I could make to save the each generated objects to each files. But, to open and to see the each files are bothered, so I wrote a code to put some objects in order to. The code is here.



It's a very interesting. So many strange objects were build, like 'Cambrian Explosion'.
And another try, I'd like to add UI for setting the parameters.

Search the tutorial for making UI for Blender2.5 on the web, and add some lines for test, but I couldn't get any change. What's wrong?


This code is for generating single object, the code is here.

Friday, May 20, 2011

How wonderful!

From the first post of this blog, it past a month. With Dolf and the other's help, I got very wonderful code. (Thanks all!)
Of course, this is not the end of project, it's still in progress.
So, the objects that some of I got today are these. With [for~] sentence, The objects are generated and save automatically.





They are so cute. (^o^) The code is here.
I have a problem(it's not such big problem). In this code, I gather the faces to 'vertex group' that I'd like to extrude before operate each face. But if two faces selected alternately, the face between the two faces is selected, and three faces are extruded. 



Thursday, May 19, 2011

It's good, it's good. \(^o^)/

I confused the code a little bit, so I tidied up the code. And changed the method for body making from array to sin curve.
This is the result.


Now, the seed object isn't necessary. This code make the object automatically.
I have to study more for the variation of the method of face selection.

<CODE>

# First import bpy to get access to well... everything in blender
import bpy
import math, mathutils, random
# 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, startAngle, stepAngle, modLevel, modRate, axis):
# 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 = startAngle
oldRatio = 1.0
# Shape
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)+modLevel*math.sin(math.radians(t+modRate)))+2.0)/oldRatio
dA = stepDist
sA = newRatio
rA = math.sin(math.radians(t*2))*stepRot
axis_x = axis[0]
axis_y = axis[1]
axis_z = axis[2]
transStep(dA, sA, rA, axis_x, axis_y, axis_z)
t = t + stepAngle
oldRatio = oldRatio*newRatio
#bpy.ops.mesh.select_all(action='DESELECT')
#bpy.ops.object.vertex_group_set_active(group='legTop')
#bpy.ops.object.vertex_group_assign(new=False)
# transformFaces!(END) --------------------------------------------------<

# bodyShape ------------------------------------------------------>
def bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axis):
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, startAngle, stepAngle, modLevel, modRate, axis)
bpy.ops.mesh.select_all(action='DESELECT')
#bpy.ops.object.vertex_group_remove(all=False)
# 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)------------------------------------------<

# -- Set Up(START) ------------------------------------------> 
bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(0, 0, 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.1, 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)
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) ------------------------------------------< 

# Generate Object ----------------------------------------->
# bodyShape(vGroup, mainLevel, stepNum, stepDist, stepRot, startAngle, stepAngle, modLevel, modRate, axisArray)
bodyShape('body', 2.0, 12, -0.5, 1.0, -120, 30, 5.0, 2.0, [-1, -2.22045e-16, -0])
cellSubdiv()
# spine
assignFaces('spine', -5.0, 5.0, 2.5, 20.0, 0.0, 10.0)
transformFaces('spine', 0.3, 10, -0.2, -0.5, -120, 10, 5, 20, [-2.22045e-16, -1, -0])


</CODE>

Wednesday, May 18, 2011

First try for Sin() modeling.

I tried a modeling method by using sin(). This is a result. It's not bad. But I have to tidy up the code, as simple as possible.


I used two math.sin() function and some rotation for 'S' shape.

Monday, May 16, 2011

Math.functional body making.

From this 'seed' object, I got this image, like a kind of plants.




It's a strange! but interesting for me.
I'm not satisfied this result yet. The functions for body making is not good. Because, it's not automatic generation, made by only preset numbers.
So, I thought a way to make from some math.functions. This is still an idea now.


Saturday, May 14, 2011

Select Faces and make details.

I thought to select some part of faces by using between Min and Max value.
It's very easy, but surely one of methods.

And I wrote some codes, the result is this.


Total code is this

<CODE>

# First import bpy to get access to well... everything in blender
import bpy
import math, mathutils, random
# transStep ---------------------------------------->
def transStep(dA, sA, srA, rA, dR, sR, rR, axis_x, axis_y, axis_z):
bpy.ops.transform.shrink_fatten(value=-dA+(dR*random.uniform(-0.5, 0.5)), 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+(sR*random.uniform(-0.5, 0.5)), (sA+(sR*random.uniform(-0.5, 0.5)))*srA, sA+(sR*random.uniform(-0.5, 0.5))), 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+(rR*random.uniform(-0.5, 0.5)),), 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! ------------------------------------------------------->
def transformFaces(vGroup, step, distArray, distRandom, scaleArray, scaleRatioArray, scaleRandom, rotArray, rotRandom, axis):
# 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

# Shape
for i in range(step):
     
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')

dA = distArray[i]
sA = scaleArray[i]
srA = scaleRatioArray[i]
rA = rotArray[i]
dR = distRandom
sR = scaleRandom
rR = rotRandom
axis_x = axis[0]
axis_y = axis[1]
axis_z = axis[2]
transStep(dA, sA, srA, rA, dR, sR, rR, axis_x, axis_y, axis_z)

#bpy.ops.object.vertex_group_set_active(group='legTop')
#bpy.ops.object.vertex_group_assign(new=False)
# transformFaces!(END) --------------------------------------------------<

# transformRegion! ---------------------------------------------------->
def transformRegion(vGroup, step, distArray, distRandom, scaleArray, scaleRatioArray, scaleRandom, rotArray, rotRandom, axis):
# Make sure nothing is selected
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
selPart(vGroup)
# 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 = 'BOUNDING_BOX_CENTER'
# Shape
for i in range(step):
     
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')

dA = distArray[i]
sA = scaleArray[i]
srA = scaleRatioArray[i]
rA = rotArray[i]
dR = distRandom
sR = scaleRandom
rR = rotRandom
axis_x = axis[0]
axis_y = axis[1]
axis_z = axis[2]
transStep(dA, sA, srA, rA, dR, sR, rR, axis_x, axis_y, axis_z)
bpy.ops.mesh.select_all(action='DESELECT')
# transformRegion(END) ----------------------------------------------------<
# bellyMaker ------------------------------------------------------>
def bellyMaker(vGroup, step, distArray, distRandom, scaleArray, scaleRatioArray, scaleRandom, rotArray, rotRandom, axisArray, ):
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, step, distArray, distRandom, scaleArray, scaleRatioArray, scaleRandom, rotArray, rotRandom, axisArray)
bpy.ops.object.vertex_group_remove(all=False)

# bellyMaker(END) -------------------------------------------------<

# headMaker ------------------------------------------------------>
def headMaker(vGroup, step, distArray, distRandom, scaleArray, scaleRatioArray, scaleRandom, rotArray, rotRandom, axisArray, ):
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, step, distArray, distRandom, scaleArray, scaleRatioArray, scaleRandom, rotArray, rotRandom, axisArray)
bpy.ops.object.vertex_group_remove(all=False)
newGroup = ob.vertex_groups.new('mouth')
bpy.ops.object.vertex_group_set_active(group='mouth')
bpy.ops.object.vertex_group_assign(new=False)

# headMaker(END) -------------------------------------------------<

# select faces from Groups
def selPart(vGroup):
bpy.ops.object.vertex_group_set_active(group=vGroup)
bpy.ops.object.vertex_group_select()
# 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")

# 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:
# See if the current face's centre is above 0.0 on the Z axis
if f.center[0] > xMin and f.center[0] < xMax:
if f.center[1] > yMin and f.center[1] < yMax:
if f.center[2] > zMin and f.center[2] < zMax:
# 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')
# -- Set Up(START) ------------------------------------------> 
# 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) ------------------------------------------< 

# Generate Object
# body and head
bellyMaker('belly', 5, [0.4, 0.2, 3, 2, 0.5], 0.0, [0.3, 1.0, 5, 0.1, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0], 0.0, [-0.2, -0.2, -0.2, -0.2, 0.0], 0.0, [-1, -2.22045e-16, -0])
headMaker('head', 4, [0.4, 0.4, 0.6, 0.8], 0.0, [0.4, 1.2, 2.0, 0.5], [1.0, 1.0, 1.0, 1.0], 0.0, [-0.2, -0.2, 0.4, 0.2], 0.0, [-1, -2.22045e-16, -0])
# mouth
transformRegion('mouth', 4, [0.3, 0.6, 0, -0.3], 0.0, [0.6, 0.4, 0.8, 1.0], [1.0, 1.0, 1.0, 1.0], 0.0, [0.7, -0.5, 0.0, 0.0], 0.0, [-1, -2.22045e-16, -0])
cellSubdiv()

# select parts basement faces
assignFaces('leg', -1.0, 1.0, -2.0, 2.0, -2.0, -0.5)
assignFaces('eye_1', -2.0, 2.0, -3.2, -2.0, 0.5, 1.5)
assignFaces('spine', -2.0, 2.0, 1.5, 6.0, 0.0, 3.0)
assignFaces('arm', -2.0, 2.0, -1.2, 1.2, 0.0, 3.0)

# transformFaces(vGroup, step, distArray, distRandom, scaleArray, scaleRatioArray, scaleRandom, rotArray, rotRandom, axisArray) 
transformFaces('spine', 3, [0.05, 0.1, 0.15], 0.0, [0.5, 0.5, 0.5], [1.5, 1.0, 1.0], 0.0, [0.0, 0.0, 0.0], 0.0, [-0, 1, -3.42285e-08])
transformFaces('arm', 5, [0.1, 0.4, 0.4, 0.4, 0.3], 0.0, [0.3, 1.8, 1.1, 0.5, 0.1], [1.0, 1.0, 1.0, 1.0, 1.0], 0.0, [0.0, -0.3, 0.3, 0.3, -0.3], 0.0, [-0, 1, -3.42285e-08])
transformFaces('eye_1', 5, [0.06, 0.015, 0.0, 0.05, 0.01], 0.0, [0.7, 0.8, 0.95, 0.7, 0.2], [1.1, 1.1, 1.1, 1.1, 1.1], 0.0, [0.0, 0.0, 0.0, 0.0, 0.0], 0.0, [-0, 1, -3.42285e-08])
#transformFaces('eye_2', 7, [0.06, 0.015, 0.0, 0.2, 0.05, 0.0, -0.1], 0.0, [1.0, 0.8, 0.95, 0.5, 0.3, 0.8, 1.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], 0.0, [0.0, 0.0, -0.2, 0.0, 0.0, 0.0, 0.0, 0.0], 0.0, [-0, 1, -3.42285e-08])
transformFaces('leg', 6, [0.1, 0.7, 0.02, 0.02, 1.0, 0.1], 0.0, [0.3, 1.6, 0.8, 1.2, 0.4, 0.1], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0], 0.0, [-0.3, -0.8, 0.0, 0.0, 1.0, 0.0], 0.0, [-0, 1, -3.42285e-08])
# transformRegion(vGroup, step, distArray, distRandom, scaleArray, scaleRatioArray, scaleRandom, rotArray, rotRandom, axisArray) 



</CODE>