Title: 3D Construction Basics in WPF
13D Construction Basics in WPF
- MN WPF/Silverlight User Group June 16th,
2009Mike Hodnick
2Agenda
- 3D construction theory
- 3D .NET classes
- Transforms
- Animation
- Texture coordinates
- Hit testing
- Real tools and data
- Resources
3About Mike Hodnick
- Lead Consultant at Inetium
- www.kindohm.com
- mike.hodnick_at_gmail.com
- _at_kindohm
43D Construction Theory
- Why points, triangles, and cross products are
important to YOU.
5Mesh Basics
- Positions the vertices of a mesh
- Triangles the polygons formed by positions
- Normals determine if a triangles surface is
lit by light
6Right-Hand Rule
- Counter-Clockwise top visible
- Clockwise bottom visible
- Not the same thing as Normals
7Cube Mesh Walkthrough
8Define Positions
9Define Triangles and Normals
Triangle 1 p0, p1, p2 Triangle 2 p0, p2,
p3 Triangle 3 p4, p7, p5 Triangle 4 p5, p7,
p6 Triangle 5 p4, p5, p0 Triangle 6 p5, p1,
p0 Triangle 7 p7, p4, p3 Triangle 8 p4, p0,
p3 Triangle 9 p6, p7, p2 Triangle 10 p7,
p3, p2 Triangle 11 p5, p6, p1 Triangle 12
p6, p2, p1Normals for Triangle3 p4
0,1,0p7 0,1,0 p5 0,1,0 Normals for
Triangle11 p5 1,0,0p6 1,0,0p1 1,0,0
103D .NET Classes
- Because coding is more fun than math.
113D .Net Classes
Viewport3D
ModelVisual3D
Camera
PerspectiveCamera
OrthographicCamera
ModelVisual3D
ModelVisual3D
ModelVisual3D
ModelVisual3D
12ModelVisual3D Content
- ModelVisual3D
- Light
- DirectionalLight
- AmbientLight
- SpotLight
ModelVisual3D -Model3DGroup -GeometryModel3D
ModelVisual3D Children -ModelVisual3D
13GeometryModel3D
GeometryModel3D
MeshGeometry3D Points Triangle Indeces Normals
MaterialDiffuseMaterial EmissiveMaterialSpecul
arMaterial
14MeshGeometry3D Class
- Positions property gets or sets the collection
of points that define the objects shape. - TriangleIndeces gets or sets the ordering of
positions by position index. Used to define
right-hand rule directions. - Normals property gets or sets the normals on
the objects points.
15PerspectiveCamera Class
- Position location of the camera
- LookDirection vector of where the camera is
looking - NearPlaneDistance minimum viewing distance
- FarPlaneDistance maximum viewing distance
- FieldOfView horizontal viewing distance
- UpDirection defines the up vector
16Create a basic scene
17Transformers
18Transforms
- Cooler than Optimus Prime.
19Transforms
- Move, scale, and rotate 3D geometries
- Transform3D
- TranslateTransform3D
- ScaleTransform3D
- RotateTransform3D
- Transform3DGroup
- Ordering is important
20Scale Transform
21Translate Transform
y
y
x
x
22Rotate Transform
y
y
Rotate 45 about the Z axis
x
x
23Rotate Translate
y
y
Rotate 45 about the Z axis, then move
x
x
24Translate Rotate
y
y
Move, then rotate 45 about the Z axis
x
x
25Transformation demo
26Animation
27Animation Overview
- System.Windows.Media.Animation.Animatable
- Any deriving class can be animated
- Example animation types
- Numeric Animation animates numeric properties
(e.g. int, double, etc). - Vector3D Animation Animates vector properties
that define a direction or axis. - Color Animation Animates color changes.
- Ordering matters when animating transforms
28Common Animation Properties
- From
- To
- RepeatBehavior
- AutoReverse
29Animation demo
30Hit Testing
- Interact with your model.
31Hit Testing
- Handle mouse events
- Use VisualTreeHelper.HitTest() method
- Inspect the HitTestResult object
32Hit Testing
33Real tools and real data.
- Enough triangles and cubes. Lets see something
real.
343DTools
- http//www.codeplex.com/3DTools
- 2D content on 3D (not just visual brushes)
- Trackball class
- Texture coordinate generation
35Petzold Media3D Library
- Visuals
- Geometries
- 3D Text
- http//www.charlespetzold.com/3D/
36Create a scene from real data
37WPF 3D Examples/Case Studies
- The North Face case study http//www.microsoft.com
/casestudies/casestudy.aspx?casestudyid201147 - The North Face demo http//channel9.msdn.com/ShowP
ost.aspx?PostID116426 - http//www.interknowlogy.com
38Resources
- WPF 3D Tutorial http//www.kindohm.com/technical/W
PF3DTutorial.htm - 3D Code Lab http//wpf.netfx3.com/files/folders/la
bs/entry9680.aspx - 3DTools http//www.codeplex.com/3DTools
- Petzold Media3D http//www.charlespetzold.com/3D/
- Karsten J http//blogs.msdn.com/karstenj
- Tim Sneath http//blogs.msdn.com/tims
- WPF3D team blog http//blogs.msdn.com/wpf3d/
39The End