Accueil > Linux / Logiciels Libres > Blender > SoftBody Text animation

SoftBody Text animation

samedi 10 mars 2012, par Yann

Une animation permettant de tester la librairie Bullet (http://bulletphysics.org/wordpress/) utilisée par Blender...

SoftBody Text animation

La librairie (http://bulletphysics.org/wordpress/) est utilisée dans Blender pour la simulation physique. Dans cette exemple, on va laisser tomber un texte sur un cylindre. Le script créé permet d’automatiser un exemple issu de http://blenderartists.org/forum/sho...

Fichier Blender
Fichier blender de démonstration
import bpy
from bpy.props import *
from math import pi

#http://www.sebastianbauer.name/archive/117
def moveToLayer( object, layer ):
    layers = [False]*20
    layers[layer] = True
    object.layers = layers

newText="printf(\"Hello World!\\n\");"
#create text
bpy.ops.object.text_add(view_align=False, enter_editmode=False,location=(0, 0, 0), rotation=(0, 0, 0))
ActiveObjectText = bpy.context.scene.objects.active
#rotating text
#angles are in radians
#bpy.ops.transform.rotate(value=(pi/2,), axis=(1.0, 0.0, 0.0), constraint_axis=(False, False, False), constraint_orientation='GLOBAL', 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)
#second solution
ActiveObjectText.rotation_euler[0]=0.0 #xaxis
ActiveObjectText.rotation_euler[1]=0.0  #yaxis
ActiveObjectText.rotation_euler[2]=0.0  #zaxis
ActiveObjectText.location[0]=0
ActiveObjectText.location[1]=-9.75
ActiveObjectText.location[2]=5 #dur to shadow on the ground
#changing text
bpy.context.scene.objects.active=ActiveObjectText
bpy.ops.object.editmode_toggle()
bpy.ops.font.delete()
bpy.ops.font.text_insert(text=newText, accent=False)
bpy.ops.object.editmode_toggle()

#centering text
ActiveObjectText.data.align='CENTER'
#extrude text
ActiveObjectText.data.extrude=0.1
#bevel text
ActiveObjectText.data.bevel_depth = 0.01
ActiveObjectText.data.bevel_resolution = 0

#convert to mesh to apply effect
bpy.ops.object.convert(target='MESH', keep_original=False)
#put origin to center of text
#bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
# Don't use Median, because it does not always put the origin to the center!
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='BOUNDS') 
#affect material
ActiveObjectText.data.materials.append(bpy.data.materials['MAT_PRE_Obsidian'])


#copy the pre loopecut cube
bpy.ops.object.select_all(action='DESELECT')
#obsolete
#bpy.ops.object.select_name(name='Enveloppe')
bpy.context.scene.objects.active = bpy.context.scene.objects['Enveloppe']
#activate in 3D
bpy.context.scene.objects.active.select = True
bpy.ops.object.duplicate(linked=False, mode='TRANSLATION')
#bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'}, TRANSFORM_OT_translate={"value":(0, 0, 0), "constraint_axis":(False, False, False), "constraint_orientation":'GLOBAL', "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), "texture_space":False, "release_confirm":False})
ActiveObjectEnveloppe = bpy.context.scene.objects.active
ActiveObjectEnveloppe.name = 'Enveloppe2'


ActiveObjectEnveloppe.draw_type = 'WIRE'
ActiveObjectEnveloppe.hide_render = True
#need to be on the visible layer to do duplication?
#moving object
ActiveObjectEnveloppe.location[0]=0
ActiveObjectEnveloppe.location[1]=-9.75
ActiveObjectEnveloppe.location[2]=5

# move to layer 0 (first one)
#moveToLayer(ActiveObjectEnveloppe,0)

#adjust size of existed envelope to text 

IncrementX = 0.3
IncrementY = 0.3
IncrementZ = 0.15
ActiveObjectEnveloppe.dimensions = (ActiveObjectText.dimensions[0]+IncrementX),(ActiveObjectText.dimensions[1]+IncrementY), (ActiveObjectText.dimensions[2]+IncrementZ)
#bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='BOUNDS')

##quads to tris to add faces : not useful
#bpy.ops.object.editmode_toggle()
#bpy.ops.mesh.select_all(action='SELECT')
#bpy.ops.mesh.quads_convert_to_tris()
#bpy.ops.object.editmode_toggle()

bpy.ops.object.modifier_add(type='SOFT_BODY')

#link text to enveloppe
bpy.ops.object.select_all(action='DESELECT')
#obsolete
#bpy.ops.object.select_name(name='Enveloppe')
bpy.context.scene.objects.active = ActiveObjectText
#activate in 3D
bpy.context.scene.objects.active.select = True
bpy.ops.object.modifier_add(type='MESH_DEFORM')
#configuring mesh deform
ActiveObjectText.modifiers['MeshDeform'].object = ActiveObjectEnveloppe
ActiveObjectText.modifiers['MeshDeform'].precision = 6 #<6 does not work!!! grid precision?
#binding text to cube
bpy.ops.object.meshdeform_bind(modifier="MeshDeform")


#softbody configuration
ActiveObjectEnveloppe.soft_body.use_goal=False

ActiveObjectEnveloppe.soft_body.use_stiff_quads = True

ActiveObjectEnveloppe.soft_body.plastic=6

Utilisation du script :

Le résultat :