Thursday, April 28, 2011

I believe we are going to good direction.

With Dolf's help, the script goes to be better and better, so this is today's result.
Oh, this is almost Dolf's code. :-(

<CODE>

# Here is how we do things separately for every face!
# In a very very simple way.


# Get access to blender through bpy and get the active object
import bpy
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')


# Now just like before we loop through all the faces, but we don't just select/deselect, we add them to a list...


# 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 fresh new empty list to put your faces in
faceList = []


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


# The index of every 5th face will be added to the list
# if i % 5 == 0:
faceList.append(f.index)


# NOW WE LOOP THROUGH THE LIST
for index in faceList:

# Make sure we are in object mode so we can select the current face in the list
bpy.ops.object.mode_set(mode='OBJECT')

# Select this face
print('selecting',index)
ob.data.faces[index].select = True

# NOW WE CAN DO WHATEVER WE WANT TO THIS FACE

# Go into edit mode for editing!
bpy.ops.object.mode_set(mode='EDIT')

# Just for fun... lets make a loop that extrudes and shrinks the face 5 times
for i in range(2):

# Extrude the current Face (We use 'REGION' because 'FACES' only works with multiple faces selected)
bpy.ops.mesh.extrude(type='REGION')

# Here's the really hacky part... to make sure the shrink works correct.. we go in and out of object mode
# That way the mesh "updates" nicely after the extrude... I do not want to do this... but it works
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')

# Transform selected faces. tValue = move
tValue = -0.2
bpy.ops.transform.shrink_fatten(value=tValue, 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.766402, 0.766402, 0.766402), 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)


# Now if we are done with this face... we deselect it, and anything else that might be selected (outside the 5 long loop)
bpy.ops.mesh.select_all(action='DESELECT')


bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
bpy.ops.object.editmode_toggle()
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.ops.object.modifier_apply(apply_as='DATA', modifier="Subsurf")
bpy.ops.object.modifier_add(type='SUBSURF')


bpy.ops.object.shade_smooth()

</CODE>

'Seed' object was 'Torus, 36 Major Segment, 9 Minor Segment'. How about this? I think it's a big big step. I didn't use 'Rotate' code, it'll be more complex shapes.


No comments:

Post a Comment