Advanced 3D Techniques with WPF.ppt
《Advanced 3D Techniques with WPF.ppt》由会员分享,可在线阅读,更多相关《Advanced 3D Techniques with WPF.ppt(56页珍藏版)》请在麦多课文档分享上搜索。
1、Advanced 3D Techniques with WPF,David Teitlebaum - Program Manager Jordan Parker - Developer Kurt Berglund - Developer Microsoft Corporation,Talk Outline,Introduction to WPF3D What do you need to do to see something? Interactive 2D on 3D Make VisualBrush work like you expected it to Performance Tips
2、 Learn how to avoid common mistakes,Jordan Parker,basics,The Name Game Warmup Time,Pattern: FooBar is a Bar with a Foo Examples: ModelVisual3D is a Visual3D with a Model3D GeometryModel3D is a Model3D with a Geometry3D MeshGeometry3D is a Geometry3D with a mesh ScaleTransform3D is a Transform3D with
3、 a scale And so on (generally) DrawingImage vs. ImageDrawing anyone?,The Near Minimal Scene,Lets do a simple 3D video example step-by-step,Our Coordinate System,Right-handed Notice that +Y is up opposite of 2D!,(Image from http:/www.willamette.edu/gorr/),MeshGeometry3D,Specifies a mesh of triangles
4、Positions: Triangle vertices TriangleIndices: Optional indices Normals: Per-vertex orientation used in lighting. Generated for you. TextureCoordinates: Describes the 2D Brush mapping. NOT generated for you. Not needed for SolidColorBrushes. Triangle vertices should be given in CCW order,TriangleIndi
5、ces,If specified:positionsindices0 positionsindices1 texcoordsindices0 texcoordsindices1 normalsindices0 normalsindices1 If not specified:positions0 positions1 texcoords0 texcoords1 normals0 normals1 ,TextureCoordinates,(image from you dont specify normals, we generate them by averaging the “real”
6、normals of the triangles that share the vertex. This gives a smooth appearance If you duplicate a vertex, it will end up with different normals each time. Triangle specification matters! If you specify too many, we throw out the extras If you specify too few, we generate the rest,Normals Cylinder Ca
7、p Generation Example,Specifying the Plane,(-1,1,0) 0 (0,0),(-1,-1,0) 1 (0,1),(1,-1,0) 2 (1,1),(1,1,0) 3 (1,0),Key:posidxtc,Looking down -Z,Mesh XAML,Well let WPF compute the normalsIn general, youll be exporting a mesh to XAML from a tool,Materials,Reflection/absorption of light EmissiveMaterial: Su
8、rface appears to give off light SpecularMaterial: Shine DiffuseMaterial: Soft scattering Takes a Brush for the base color Combine them with MaterialGroup When in doubt, use DiffuseMaterial,Material Examples,Video DiffuseMaterial XAML,(In code, you could use a DrawingBrush w/ a VideoDrawing instead),
9、GeometryModel3D,Combines the Material and the Geometry3D Allows you to specify a transform,(the plane mesh)(the video material),Lights,Not unlike reality, without light you cant see anything* AmbientLight: Equal contribution everywhere DirectionalLight: The sun PointLight: Light bulb SpotLight: Self
10、 explanatory Lights are Model3Ds and thus have transforms Well use an AmbientLight in our example for simplicity,* Except EmissiveMaterials,Model3DGroup,(the ambient light)(the plane GeometryModel3D) ,Group multiple Model3Ds together Is a Model3D,Visual3D,3D analog of the 2D Visual class You need at
11、 least one just like you need at least one Visual in 2D (FrameworkElements are Visuals) To draw a Model3D, use ModelVisual3D,(the Model3DGroup),Cameras,Determine what part of the scene you see and project 3D onto a 2D plane OrthographicCamera: parallel lines stay parallel PerspectiveCamera: perspect
12、ive foreshortening MatrixCamera: Specify your own projection,Viewport3D,The bridge between the 2D and 3D world It is a FrameworkElement Takes a Camera and the root of your Visual3D tree,(the PerspectiveCamera)(the ModelVisual3D) ,3D Video,demo,Kurt Burglund,Interactive 2D on 3D,Flickr Photo Browser,
13、demo,Using Interactive 2D on 3D,Interactive3DDecorator Goes around the Viewport3D you want to make interactive InteractiveVisual3D Subclass of ModelVisual3D used to add interactive 2D on 3D Has DependencyProperties Geometry, Visual, and Material used to set the appearance of the object,Interactive 2
14、D on 3D Example - Before,Interactive 2D on 3D Example - After,How it works,Hidden visual layer placed above Viewport3D 2D on 3D that the mouse is over is placed in hidden layer Layer moved so that the point the mouse is over in 3D is the same as the point the mouse is over in the hidden layer,Hit Te
15、sting,public void HitTest(object sender, System.Windows.Input.MouseButtonEventArgs args) Point mouseposition = args.GetPosition(myViewport); PointHitTestParameters pointparams = new PointHitTestParameters(mouseposition); VisualTreeHelper.HitTest(myViewport, null, HTResult, pointparams); public HitTe
16、stResultBehavior HTResult(System.Windows.Media.HitTestResult rawresult) RayHitTestResult rayResult = rawresult as RayHitTestResult; if (rayResult != null) RayMeshGeometry3DHitTestResult rayMeshResult = rayResult as RayMeshGeometry3DHitTestResult;if (rayMeshResult != null) return HitTestResultBehavio
17、r.Continue; ,Hit Testing Return Results,RayMeshGeometry3DHitTestResult contains all the information about the hit test Point, Mesh, Model, Visual3D hit Vertex indices of triangle hit Barycentric coordinates for point of intersection: can be used to compute texture coordinate of intersection,Barycent
18、ric Coordinates,Weighted sum of triangles vertices p = VertexWeight1 * v1 + VertexWeight2 * v2 + VertexWeight3 * v3 Can be extended to texture coordinates uv = VertexWeight1 * uv1 + VertexWeight2 * uv2 + VertexWeight3 * uv3 Use to figure out where on texture you are,Filling the Viewport3D,Say we wan
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ADVANCED3DTECHNIQUESWITHWPFPPT
