O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Blender 2.49 Scripting

Book Description

If you already know Blender and some Python, this book will help you greatly increase the power and flexibility of this tool. Learn in easy steps how to use scripting to add brand new functions and efficiencies.

  • Gain control of all aspects of Blender using the powerful Python language

  • Create complex meshes programmatically and apply materials and textures

  • Automate the rendering process and extend Blender's image manipulation capabilities

  • Extend Blender's built-in editor

  • Interact with version control systems and store render results on a FTP server

  • In Detail

    Blender 3D is a popular, open source modeling package that can produce photo-realistic 3D images and animations. Automating tasks and extending the functionality of an extensive application like Blender will streamline your workflow and make the impossible possible. However, implementing scripts may be daunting.

    This book takes a practical step-by-step approach to implementing Python scripts that cover almost all areas of Blender. It clearly outlines each problem and focuses on straightforward, easy-to-understand code, highlighting the common pitfalls and Blender idiosyncrasies. It guides you from the installation process and the creation of a simple object to elaborate, fully rigged models with vertex groups and materials all the way to extending Blender's built-in editor. It also teaches how to implement a simple web server inside Blender to serve rendered images. This book will take you from a clear problem description to a fully functional program. The focus is on finding your way in Blender's vast array of possibilities and getting things done without losing too much time on programming details. Each script is carefully explained to provide insight that can be reused in other projects.

    This practical book will help you gain control over all the aspects of Blender using the Python programming language

    Table of Contents

    1. Blender 2.49 Scripting
      1. Blender 2.49 Scripting
      2. Credits
      3. About the Author
      4. About the Reviewer
      5. Preface
        1. What this book covers
        2. What you need for this book
        3. Who is this book for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      6. 1. Extending Blender with Python
        1. The Blender API
          1. A lot of power
          2. Some batteries included
          3. Check for a full Python distribution
          4. Installing a full Python distribution
          5. The interactive Python console
        2. Exploring built-in modules, the help() function
          1. Exploring built-in functions, the dir() function
        3. Getting familiar with the built-in editor
          1. An editor example
        4. First steps: Hello world
          1. Integrating a script in Blender's menus
          2. Integrating a script in Blender's help system
        5. Don't get confused, stay objective
        6. Adding different types of object from a script
          1. Adding a mesh object
          2. Distributing scripts
          3. The Blender API
          4. The Blender module
          5. Blender objects
          6. The bpy module
          7. Drawing on the screen
          8. Utilities
            1. Summary
      7. 2. Creating and Editing Objects
        1. Creepy crawlies—a GUI to configure objects
          1. Building the user interface
          2. Creating bugs—some assembly required
          3. Creating a user interface
          4. Remembering choices
          5. The full power of Blender graphics
          6. Creating a new Mesh object
        2. Transforming mesh topology
          1. Code outline bridging edge loops
        3. Dazzle your boss—bar charts in Blender style
          1. The bar chart script
        4. Weird faces—selecting and editing faces in meshes
        5. Selecting warped (non-planar) quads
          1. Code outline warp select
        6. Selecting ultra sharp faces
        7. Selecting vertices with many edges
        8. Selecting poles
          1. Selecting poles, again
        9. Determining the volume of a mesh
        10. Determining the centre of mass of a mesh
          1. Some remarks about accuracy
        11. Growing sunflowers—parenting and grouping objects
          1. Groups
          2. Parenting
          3. Growing a sunflower from a seed
          4. Duplication versus instantiation
          5. Growing a sunflower
        12. Summary
      8. 3. Vertex Groups and Materials
        1. Vertex groups
          1. A weighty issue
            1. Code outline: leftright.py
        2. Modifiers
          1. Engraving
            1. Converting a Text3d object to a mesh
            2. Extruding an edge loop
            3. Expanding an edge loop
          2. Putting it all together: Engrave.py
          3. Flying sparks
            1. Calculating the local curvature
            2. Code outline: curvature.py
            3. Putting it all together: St. Elmo's fire
        3. Bones
          1. Tick-Tock
            1. Code outline: clock.py
          2. Get a bit of backbone boy!
        4. Materials
          1. Object materials versus ObData materials
          2. Assigning materials to parts of an Object
          3. Vertex colors versus face materials
          4. Adding materials to our engraving
        5. Summary
      9. 4. Pydrivers and Constraints
        1. Getting to grips with animated properties
          1. IPO
          2. IPOchannels and IPOCurves
          3. Constraints
        2. Difference between drivers and constraints
        3. Programming with constraints
        4. Programming with IPOs
        5. PyDrivers
        6. PyConstraints
        7. Setting the time—one to rule them all
          1. Shortcuts
            1. Overcoming limitations: pydrivers.py
        8. Internal combustion—correlating complex changes
          1. More power—combining multiple cylinders to an engine
        9. Adding simple constraints
        10. Defining complex constraints
          1. The Blender constraint template
          2. Do you find me attractive too?
          3. Snapping to mesh vertices
          4. Aligning along a vertex normal
          5. Snap to vertices in a vertex group
        11. Summary
      10. 5. Acting on Frame Changes
        1. Animating the visibility of objects
          1. Fading a material
          2. Changing layers
        2. Countdown—animating a timer with script links
        3. I'll keep an eye on you
          1. Code outline: AuraSpaceHandler.py
          2. Using themes
        4. Revisiting mesh—making an impression
          1. The user interface
          2. Calculating an impression
        5. Summary
      11. 6. Shape Keys, IPOs, and Poses
        1. A touchy subject—defining an IPO from scratch
          1. Code outline: orbit.py
        2. A lot to swallow—defining poses
          1. Application of peristaltic.py to an armature
        3. Get down with the beat—syncing shape keys to sound
          1. Manipulating sound files
            1. Code outline: Sound.py
          2. Animating a mesh by a .wav file: the workflow
        4. Summary
      12. 7. Creating Custom Shaders and Textures with Pynodes
        1. The basics
          1. From nodes to Pynodes
        2. Regular tilings
          1. Anti-aliasing
          2. Indexing a texture by vector
          3. A fresh breeze—textures with normals
        3. Raindrops—animated Pynodes
          1. Render-time parameters
          2. What looks good, is good
          3. Storing expensive results for reuse
          4. Calculating normals
          5. Putting it all together
        4. Wuthering heights—a slope-dependent material
          1. Determining the slope
          2. World space versus camera space
        5. Soap bubbles—a view-dependent shader
        6. Summary
      13. 8. Rendering and Image Manipulation
        1. A different view—combining multiple camera angles
          1. Code outline—combine.py
          2. Workflow—how to showcase your model
        2. Now, strip—creating a film strip from an animation
          1. Workflow—using strip.py
        3. Rendering billboards
          1. Workflow—using cardboard.py
        4. Generating CAPTCHA challenges
          1. Design of a CAPTCHA server
        5. Summary
      14. 9. Expanding your Toolset
        1. To the Web and beyond—publish a finished render with FTP
        2. Spring cleaning—archive unused images
        3. Extending the editor—searching with regular expressions
        4. Extending the editor—interacting with Subversion
          1. Committing a file to the repository
          2. Updating a file from the repository
          3. Working with a repository
        5. The need for speed—using Psyco
          1. Enabling Psyco
        6. Summary
      15. A. Links and Resources
        1. General Blender-related forums and blogs
        2. Python programming
        3. Blender scripting
        4. External packages used in this book
        5. Other sources of information
      16. B. Commfon Pitfalls
        1. Read the API documents
        2. The trouble with import
        3. Installing a full Python distribution
      17. C. Future Developments
        1. Blender
        2. Python