#!BPY # ######################################################################## # # Text Warp - Adds and warps 3D text around the cursor position. # Copyright (C) 2007 Dave Jarvis (http://www.davidjarvis.ca) # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # # ######################################################################## import Blender, math from Blender import Curve, CurNurb, Scene, Text3d, Object, Camera from Blender import Window, Mathutils, BezTriple, Draw # Change this value to the amount of extrusion for the text. # PARAM_EXTRUDE = 0.100 # Change this value to the amount of bevelling for the text. # PARAM_BEVEL = 0.010 # Change this to the distance the text should be moved from the cursor. # Larger values will stretch the warp, as though the warp was trying to # wrap its arms around a larger tree. A smaller value equates to a smaller # tree hugging. Love love love. # PARAM_SHIFT_Y = -1.5 # The word(s) to be warped. # PARAM_TEXT = "Text" # ######################################################################## # DESCRIPTION # Simulates a key press. # # PARAM key - Key to be pressed; see Blender.Draw for keys. # PARAM qual - Modifier keys (e.g., shift); see Window.Qual. Set to False # if no modifier keys should be held. # # ######################################################################## def keypress( key, qual ): id = Window.GetScreenInfo( Window.Types.VIEW3D )[0]['id'] if qual: Window.SetKeyQualifiers( qual ) Window.QAdd( id, key, 1 ) Window.QHandle( id ) Window.Redraw() Window.SetKeyQualifiers( 0 ) Window.QHandle( id ) Window.Redraw() # ######################################################################## # DESCRIPTION # Simulates converting an object to a different type. Unfortunately, a # menu pops up and takes away all subsequent keyboard inputs, so there is # no way to currently emulate a menu selection. Thus you will have to # press Enter (or Return) to manually accept the conversion to either the # Curve or Mesh. The Mesh is the ultimate conversion with Curve being an # interim. As the script runs, simply press Enter to acknowledge both # popup windows when they appear. # # ######################################################################## def convert( object ): keypress( Draw.CKEY, Window.Qual.ALT ) # ######################################################################## # DESCRIPTION # Smooths all the faces for an object. Technically, this should be a # method included with Blender.Object.Object. # # PARAM object - The object to smoooooooth, like buttah. # # ######################################################################## def smooth( object ): mesh = object.getData( False, True ) for face in mesh.faces: face.smooth = True # ######################################################################## # DESCRIPTION # Centres an object around the current cursor position. # # PARAM object - The object to centre. # # ######################################################################## def centreCursor( object ): bounds = object.getBoundBox() sx = 0.0 sy = 0.0 sz = 0.0 for bound in bounds: sx += bound[0] sy += bound[1] sz += bound[2] object.LocX = -sx / 8 object.LocY = sy / 8 object.LocZ = -sz / 8 # Change to the front view. # keypress( Draw.PAD1, False ) # Use the current scene for the new text. # scene = Scene.GetCurrent() # Deselect all other objects # for ob in Object.Get(): ob.select( 0 ) # Create the 3D text object; soon to be warped text. # text = Text3d.New( PARAM_TEXT ) text.setText( PARAM_TEXT ) # Place the object into the scene, with wreckless abandon. # object = Object.New( "Text" ) object.link( text ) scene.link( object ) object.select( 1 ) # Set extrusion levels. You did set these, right? # text.setExtrudeDepth( PARAM_EXTRUDE ) text.setExtrudeBevelDepth( PARAM_BEVEL ) # Align the object to allow warping from above. # object.RotX = 90.0 * math.pi / 180 # Convert the Text to a Curve (requires user interaction). # convert( object ) # Convert the Curve to a Mesh (requires user interaction). # convert( object ) # Smooth the object. # smooth( object ) # Switch to Edit mode. # Window.EditMode( 1 ) # Select all vertices. # keypress( Draw.AKEY, False ) # Beautify, five times. # keypress( Draw.FKEY, Window.Qual.ALT ) keypress( Draw.FKEY, Window.Qual.ALT ) keypress( Draw.FKEY, Window.Qual.ALT ) keypress( Draw.FKEY, Window.Qual.ALT ) keypress( Draw.FKEY, Window.Qual.ALT ) # Convert triangle faces to quadrangles, two times. # keypress( Draw.JKEY, Window.Qual.ALT ) keypress( Draw.JKEY, Window.Qual.ALT ) # Mirror X local. # keypress( Draw.MKEY, Window.Qual.CTRL ) # Shift the object back to the cursor. # centreCursor( object ) # Move the object away from the cursor. # object.LocY = object.LocY + PARAM_SHIFT_Y # Change to the top view. # keypress( Draw.PAD7, False ) # Warp the text. Finally! # keypress( Draw.WKEY, Window.Qual.SHIFT ) # Technically, another variable could be parsed to figure out the exact # keypresses required to enter in the degrees for the warp, but a manual # solution should suffice. Besides, interactivity gives more control. ;-) # # The commented lines below, for example, should warp by 120 degrees. # Not tested. Buyer beware. Use at own risk. Comes without warranty, either # expressed or implied. # #keypress( Draw.ONEKEY, False ) #keypress( Draw.TWOKEY, False ) #eypress( Draw.ZEROKEY, False ) #keypress( Draw.RETKEY, False ) # Exit Edit mode # Window.EditMode( 0 ) # Make it so. # Blender.Redraw() object.makeDisplayList()