logo资料库

Character-Animation-With-Direct3D.pdf

第1页 / 共448页
第2页 / 共448页
第3页 / 共448页
第4页 / 共448页
第5页 / 共448页
第6页 / 共448页
第7页 / 共448页
第8页 / 共448页
资料共448页,剩余部分请下载后查看
Acknowledgments
About the Author
Contents
Introduction
1 Introduction to Character Animation
What Is Character Animation?
A Brief History of Character Animation
Morphing Animation and Skeletal Animation
The Soldier
Coding Conventions
Conclusions
Further Reading
2 A Direct3D Primer
DirectX 9 versus DirectX 10
STL and the D3DX Library
Setting Up a Project in Visual Studio Express 2008
VC++ Directories
Creating a New Project
Linking DirectX Libraries
Application Framework
WinMain
Creating the Window
Basic Rendering
Creating the DirectX Device
Direct3D Rendering Loop
Loading a Mesh
Loading an Effect
Rendering a Mesh with an Effect
Conclusions
Further Reading
3 Skinned Meshes
Skinned Meshes Overview
Bone Hierarchies
The D3DXFRAME Structure
Loading a Bone Hierarchy
The CreateFrame() Function
The CreateMeshContainer() Function
The DestroyFrame() Function
The DestroyMeshContainer() Function
The ID3DXAllocateHierarchy
Applying a Mesh to the Bone Hierarchy
Software Skinning Overview
Hardware Skinning Overview
Software Skinning Implementation
Hardware Skinning Implementation
Rendering Static Meshes in Bone Hierarchies
Conclusions
Chapter 3 Exercises
Further Reading
4 Skeletal Animation
Keyframe Animation
Animation Sets
The ID3DXAnimationController Interface
Loading the Animation Data
Multiple Animation Controllers
Conclusions
Chapter 4 Exercises
5 Advanced Skeletal Animation Techniques
The Track Structure
Blending Multiple Animations
Compressing Animation Sets
Animation Callback Events
Motion Capture (Mocap)
Optical Motion Capture Systems
Magnetic Motion Capture Systems
Mechanical Motion Capture Systems
Comparison of the Different Mocap Systems
Lapland Studio Interview
Conclusions
Chapter 5 Exercises
Further Reading
6 Physics Primer
Introduction to Rigid Body Physics
Forces
The Effect of Forces on a Rigid Body
Quaternions
Describing the World
The Oriented Bounding Box Class
Physics Simulation
Position, Velocity, and Acceleration
The Particle
The Spring
Conclusions
Chapter 6 Exercises
Further Reading
7 Ragdoll Simulation
Introduction to the Bullet Physics Engine
Integrating the Bullet Physics Library
Download Bullet
Build the Bullet Libraries
Setting Up a Custom Direct3D Project
Hello btDynamicsWorld
Constraints
Constructing the Ragdoll
Updating the Character Mesh from the Ragdoll
Getting a Bone’s Position from an OBB
Getting a Bone’s Orientation from an OBB
Updating the Bone Hierarchy
Conclusions
Chapter 7 Exercises
8 Morphing Animation
Basics of Morphing Animation
Using Multiple Morph Targets
Morphing Animation on the GPU
Custom Vertex Formats
Creating the Morph Vertex Declaration
The Morphing Vertex Shader
Combining Skeletal and Morphing Animation
Skeletal/Morphing Vertex Format
Skeletal/Morphing Vertex Shader
Conclusions
Chapter 8 Exercises
9 Facial Animation
Facial Animation Overview
Facial Expressions
The Eye of the Beholder
The Face Class
Loading Multiple Targets from One .X File
Extracting Meshes from a D3DXFRAME Hierarchy
Implementing the Face Class
The Face Controller Structure
Animation Channels
Face Factory
Conclusions
Chapter 9 Exercises
10 Making Characters Talk
Phonemes
Visemes
Basics of Speech Analysis
Sound Data
The WAVE Format
Automatic Lip-Syncing
Conclusions
Further Reading
11 Inverse Kinematics
Introduction to Inverse Kinematics
Solving the IK Problem
Look-At Inverse Kinematics
Two-Joint Inverse Kinematics
Conclusions
Chapter 11 Exercises
Further Reading
12 Wrinkle Maps
Introduction to Normal Mapping
What Are Normal Maps?
Encoding Normals as Color
Putting the Normal Map to Use
The TBN-Matrix
Converting a Mesh to Support Normal Mapping
The Normal Mapping Shader
Creating Normal Maps
Creating Normal Maps in Practice
Specular Highlight
Specular Maps
Wrinkle Maps
Conclusions
Chapter 12 Exercises
Further Reading
13 Crowd Simulation
Flocking Behaviors
Boids
Introduction to Crowd Simulation
Smart Objects
Following a Terrain
Conclusions
Chapter 13 Exercises
Further Reading
14 Character Decals
Introduction to Decals
Picking a Hardware-Rendered Mesh
Creating Decal Geometry
Calculating the Exact Hit Position
Selecting Triangles for the Decal Mesh
Copying the Skinning Information
The CharacterDecal Class
Calculating Decal UV Coordinates
Conclusions
Chapter 14 Exercises
15 Hair Animation
Hair Representation
Hair Modeling
The Control Hair Class
The HairPatch Class
Growing the Hair
Rendering the Hair Patch
Creating a Haircut
Animating the Control Hairs
The Hair Class
Conclusions
Chapter 15 Exercises
Further Reading
16 Putting It All Together
Attaching the Head to the Body
The Character Class
Future Work
Character Level-of-Detail
Root Motion versus Non-Root Motion
Animation Trees/Animation Graph
Track Masks
Separate Mesh and Animation Files
Alan Wake Case Study
Interview with Sami Vanhatalo, Senior Technical Artist
Interview with Henrik Enqvist, Animation Programmer
Final Thoughts
Further Reading
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Z
CHARACTER ANIMATION WITH DIRECT3D® CARL GRANBERG Charles River Media A part of Course Technology, Cengage Learning Australia, Brazil, Japan, Korea, Mexico, Singapore, Spain, United Kingdom, United States
Character Animation with Direct3D® © 2009 Course Technology, a part of Cengage Learning. Carl Granberg Publisher and General Manager, Course Technology PTR: Stacy L. Hiquet Associate Director of Marketing: Sarah Panella Content Project Manager: Jessica McNavich Marketing Manager: Jordan Casey Senior Acquisitions Editor: Emi Smith Project Editor and Copy Editor: Dan Foster, Scribe Tribe Technical Reviewer: Henrik Enqvist CRM Editorial Services Coordinator: Jennifer Blaney Editorial Services Coordinator: Jen Blaney Interior Layout: Jill Flores Cover Designer: Mike Tanamachi CD-ROM Producer: Brandon Penticuff Indexer: Valerie Haynes Perry Proofreader: Ruth Saavedra and Mike Beady ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the publisher. For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 For permission to use material from this text or product, submit all requests online at cengage.com/permissions Further permissions questions can be emailed to permissionrequest@cengage.com Microsoft, Windows, Direct3D, and DirectX are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Library of Congress Control Number: 2008931080 ISBN-13: 978-1-58450-570-9 ISBN-10: 1-58450-570-2 eISBN-10: 1-58450-630-X Course Technology, a part of Cengage Learning 20 Channel Center Street Boston, MA 02210 USA Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at: international. cengage.com/region Cengage Learning products are represented in Canada by Nelson Education, Ltd. For your lifelong learning solutions, visit courseptr.com Visit our corporate website at cengage.com Printed in the United States of America 1 2 3 4 5 6 7 11 10 09
To Aino… again.
Acknowledgments As always with a project such as this, there’s a long list of people deserving my thanks. Writing a book is not a small feat (yes, patting myself on the back), and it is also some- thing I could not have done alone. So first off I must thank the people of Charles River Media for wanting to publish this hunk of technical mumbo jumbo, and especially Emi Smith, my editor. Big thanks also to Dan Foster, my project editor, and Henrik Enqvist of Remedy Entertainment, my technical editor. Henrik also supplied the code for the Inverse Kinematics chapter and the Wrinkle Maps example, for which I owe him thanks. Next I’d like to thank my friend Markus Tuppurainen for supplying some of the art for this book—sketches and pixel characters—as well as for helping me make the Soldier model. Finally I’d like to thank my wife and my family for their support through this last year, which has been challenging in many ways. Last, but not least, thank you for buying this book. I hope you enjoy it and also learn something from it. About the Author Carl Granberg has been creating games on a hobby basis since the old DOS-based Mode 13h graphics, after which he moved on to DirectDraw and finally Direct3D graphics. He received his master of science in computing at Curtin University, Perth, Australia, and has since been working in the Finnish game industry for 3 years. He is currently working as a Tools programmer at Remedy Entertainment in Finland. He’s also involved with a group of hobby game developers that goes by the name of BugFactory (www.bugfactory.fi), which has just released its first title, The Tales of Bingwood. For matters relating to this book, he can be contacted at carl@bugfactory.fi. iv
Contents Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xi 1 Introduction to Character Animation . . . . . . . . . . . . . . . . . . . . . . . . .1 What Is Character Animation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 A Brief History of Character Animation . . . . . . . . . . . . . . . . . . . . . . . . . .2 Morphing Animation and Skeletal Animation . . . . . . . . . . . . . . . . . . . . .5 The Soldier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 Coding Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10 2 A Direct3D Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 DirectX 9 versus DirectX 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 STL and the D3DX Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 Setting Up a Project in Visual Studio Express 2008 . . . . . . . . . . . . . . .15 VC++ Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15 Creating a New Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 Linking DirectX Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18 Application Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19 WinMain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21 Creating the Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22 Basic Rendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24 Creating the DirectX Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25 Direct3D Rendering Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .26 Loading a Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27 v
vi Contents Loading an Effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28 Rendering a Mesh with an Effect . . . . . . . . . . . . . . . . . . . . . . . . . . . .30 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32 3 Skinned Meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33 Skinned Meshes Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34 Bone Hierarchies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35 The D3DXFRAME Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37 Loading a Bone Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40 The CreateFrame() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41 The CreateMeshContainer() Function . . . . . . . . . . . . . . . . . . . . . . . .41 The DestroyFrame() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42 The DestroyMeshContainer() Function . . . . . . . . . . . . . . . . . . . . . . .42 The ID3DXAllocateHierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42 Applying a Mesh to the Bone Hierarchy . . . . . . . . . . . . . . . . . . . . . . . .47 Software Skinning Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49 Hardware Skinning Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .49 Software Skinning Implementation . . . . . . . . . . . . . . . . . . . . . . . . . .50 Hardware Skinning Implementation . . . . . . . . . . . . . . . . . . . . . . . . .59 Rendering Static Meshes in Bone Hierarchies . . . . . . . . . . . . . . . . . . .67 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71 Chapter 3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .72 4 Skeletal Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73 Keyframe Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74 Animation Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76 The ID3DXAnimationController Interface . . . . . . . . . . . . . . . . . . . . . . .79 Loading the Animation Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79 Multiple Animation Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83 Chapter 4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .84
Contents vii 5 Advanced Skeletal Animation Techniques . . . . . . . . . . . . . . . . . . . .85 The Track Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .86 Blending Multiple Animations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88 Compressing Animation Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90 Animation Callback Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92 Motion Capture (Mocap) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96 Optical Motion Capture Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . .97 Magnetic Motion Capture Systems . . . . . . . . . . . . . . . . . . . . . . . . . .98 Mechanical Motion Capture Systems . . . . . . . . . . . . . . . . . . . . . . . .99 Comparison of the Different Mocap Systems . . . . . . . . . . . . . . . . .100 Lapland Studio Interview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107 Chapter 5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107 6 Physics Primer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109 Introduction to Rigid Body Physics . . . . . . . . . . . . . . . . . . . . . . . . . . .110 Forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111 The Effect of Forces on a Rigid Body . . . . . . . . . . . . . . . . . . . . . . . .112 Quaternions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114 Describing the World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .119 The Oriented Bounding Box Class . . . . . . . . . . . . . . . . . . . . . . . . . .120 Physics Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .124 Position, Velocity, and Acceleration . . . . . . . . . . . . . . . . . . . . . . . . .126 The Particle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128 The Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .131 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .134 Chapter 6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135 Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135
分享到:
收藏