1.  
  1. 以下xmal是我从msdn上复制下来的。是用于在wpf中创建3d模型的实例
    链接https://msdn.microsoft.com/zh-cn/library/ms747437.aspx
    看它的使用方式。我画了个比较马虎的逻辑图。
  1. 1 <UserControl x:Class="HostingWpfUserControlInWf.UserControl1"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. >
  5.  
  6. <Grid>
  7.  
  8. <!-- Place a Label control at the top of the view. -->
  9. <Label
  10. HorizontalAlignment="Center"
  11. TextBlock.TextAlignment="Center"
  12. FontSize="20"
  13. Foreground="Red"
  14. Content="Model: Cone"/>
  15.  
  16. <!-- Viewport3D is the rendering surface. -->
  17. <Viewport3D Name="myViewport" >
  18.  
  19. <!-- Add a camera. -->
  20. <Viewport3D.Camera>
  21. <PerspectiveCamera
  22. FarPlaneDistance="20"
  23. LookDirection="0,0,1"
  24. UpDirection="0,1,0"
  25. NearPlaneDistance="1"
  26. Position="0,0,-3"
  27. FieldOfView="45" />
  28. </Viewport3D.Camera>
  29.  
  30. <!-- Add models. -->
  31. <Viewport3D.Children>
  32.  
  33. <ModelVisual3D>
  34. <ModelVisual3D.Content>
  35.  
  36. <Model3DGroup >
  37. <Model3DGroup.Children>
  38.  
  39. <!-- Lights, MeshGeometry3D and DiffuseMaterial objects are added to the ModelVisual3D. -->
  40. <DirectionalLight Color="#FFFFFFFF" Direction="3,-4,5" />
  41.  
  42. <!-- Define a red cone. -->
  43. <GeometryModel3D>
  44.  
  45. <GeometryModel3D.Geometry>
  46. <MeshGeometry3D
  47. Positions="0.293893 -0.5 0.404509 0.475528 -0.5 0.154509 0 0.5 0 0.475528 -0.5 0.154509 0 0.5 0 0 0.5 0 0.475528 -0.5 0.154509 0.475528 -0.5 -0.154509 0 0.5 0 0.475528 -0.5 -0.154509 0 0.5 0 0 0.5 0 0.475528 -0.5 -0.154509 0.293893 -0.5 -0.404509 0 0.5 0 0.293893 -0.5 -0.404509 0 0.5 0 0 0.5 0 0.293893 -0.5 -0.404509 0 -0.5 -0.5 0 0.5 0 0 -0.5 -0.5 0 0.5 0 0 0.5 0 0 -0.5 -0.5 -0.293893 -0.5 -0.404509 0 0.5 0 -0.293893 -0.5 -0.404509 0 0.5 0 0 0.5 0 -0.293893 -0.5 -0.404509 -0.475528 -0.5 -0.154509 0 0.5 0 -0.475528 -0.5 -0.154509 0 0.5 0 0 0.5 0 -0.475528 -0.5 -0.154509 -0.475528 -0.5 0.154509 0 0.5 0 -0.475528 -0.5 0.154509 0 0.5 0 0 0.5 0 -0.475528 -0.5 0.154509 -0.293892 -0.5 0.404509 0 0.5 0 -0.293892 -0.5 0.404509 0 0.5 0 0 0.5 0 -0.293892 -0.5 0.404509 0 -0.5 0.5 0 0.5 0 0 -0.5 0.5 0 0.5 0 0 0.5 0 0 -0.5 0.5 0.293893 -0.5 0.404509 0 0.5 0 0.293893 -0.5 0.404509 0 0.5 0 0 0.5 0 "
  48. Normals="0.7236065,0.4472139,0.5257313 0.2763934,0.4472138,0.8506507 0.5308242,0.4294462,0.7306172 0.2763934,0.4472138,0.8506507 0,0.4294458,0.9030925 0.5308242,0.4294462,0.7306172 0.2763934,0.4472138,0.8506507 -0.2763934,0.4472138,0.8506507 0,0.4294458,0.9030925 -0.2763934,0.4472138,0.8506507 -0.5308242,0.4294462,0.7306172 0,0.4294458,0.9030925 -0.2763934,0.4472138,0.8506507 -0.7236065,0.4472139,0.5257313 -0.5308242,0.4294462,0.7306172 -0.7236065,0.4472139,0.5257313 -0.858892,0.429446,0.279071 -0.5308242,0.4294462,0.7306172 -0.7236065,0.4472139,0.5257313 -0.8944269,0.4472139,0 -0.858892,0.429446,0.279071 -0.8944269,0.4472139,0 -0.858892,0.429446,-0.279071 -0.858892,0.429446,0.279071 -0.8944269,0.4472139,0 -0.7236065,0.4472139,-0.5257313 -0.858892,0.429446,-0.279071 -0.7236065,0.4472139,-0.5257313 -0.5308242,0.4294462,-0.7306172 -0.858892,0.429446,-0.279071 -0.7236065,0.4472139,-0.5257313 -0.2763934,0.4472138,-0.8506507 -0.5308242,0.4294462,-0.7306172 -0.2763934,0.4472138,-0.8506507 0,0.4294458,-0.9030925 -0.5308242,0.4294462,-0.7306172 -0.2763934,0.4472138,-0.8506507 0.2763934,0.4472138,-0.8506507 0,0.4294458,-0.9030925 0.2763934,0.4472138,-0.8506507 0.5308249,0.4294459,-0.7306169 0,0.4294458,-0.9030925 0.2763934,0.4472138,-0.8506507 0.7236068,0.4472141,-0.5257306 0.5308249,0.4294459,-0.7306169 0.7236068,0.4472141,-0.5257306 0.8588922,0.4294461,-0.27907 0.5308249,0.4294459,-0.7306169 0.7236068,0.4472141,-0.5257306 0.8944269,0.4472139,0 0.8588922,0.4294461,-0.27907 0.8944269,0.4472139,0 0.858892,0.429446,0.279071 0.8588922,0.4294461,-0.27907 0.8944269,0.4472139,0 0.7236065,0.4472139,0.5257313 0.858892,0.429446,0.279071 0.7236065,0.4472139,0.5257313 0.5308242,0.4294462,0.7306172 0.858892,0.429446,0.279071 " TriangleIndices="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 " />
  49. </GeometryModel3D.Geometry>
  50.  
  51. <GeometryModel3D.Material>
  52. <DiffuseMaterial>
  53. <DiffuseMaterial.Brush>
  54. <SolidColorBrush
  55. Color="Red"
  56. Opacity="1.0"/>
  57. </DiffuseMaterial.Brush>
  58. </DiffuseMaterial>
  59. </GeometryModel3D.Material>
  60.  
  61. </GeometryModel3D>
  62.  
  63. </Model3DGroup.Children>
  64. </Model3DGroup>
  65.  
  66. </ModelVisual3D.Content>
  67.  
  68. </ModelVisual3D>
  69.  
  70. </Viewport3D.Children>
  71.  
  72. </Viewport3D>
  73. </Grid>
  74.  
  75. </UserControl>
  76.  
  1.  

其实,最为关键的ModelView3D还有其他用法,比如ModelView3D.Content下只放个Model3DGroup,Model3DGroup下写个DirectionalLight,、ModelView3D再另外写个Children,下面放一些模型,也就是灯光放在Content里面,模型放在Children里面。例如上面的xmal代码可以改为:

  1. <UserControl
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="WpfControlLibrary1.UserControl1"
  5. d:DesignWidth="300" d:DesignHeight="200"
  6. >
  7.  
  8. <Grid>
  9.  
  10. <!-- Place a Label control at the top of the view. -->
  11. <Label
  12. HorizontalAlignment="Center"
  13. TextBlock.TextAlignment="Center"
  14. FontSize="20"
  15. Foreground="Red"
  16. Content="Model: Cone"/>
  17.  
  18. <!-- Viewport3D is the rendering surface. -->
  19. <Viewport3D x:Name="myViewport" >
  20.  
  21. <!-- Add a camera. -->
  22. <Viewport3D.Camera>
  23. <PerspectiveCamera
  24. FarPlaneDistance="20"
  25. LookDirection="0,0,1"
  26. UpDirection="0,1,0"
  27. NearPlaneDistance="1"
  28. Position="0,0,-3"
  29. FieldOfView="45" />
  30. </Viewport3D.Camera>
  31.  
  32. <!-- Add models. -->
  33.  
  34. <ModelVisual3D>
  35. <ModelVisual3D.Children>
  36. <ModelVisual3D>
  37. <ModelVisual3D.Content>
  38. <Model3DGroup>
  39. <Model3DGroup.Children>
  40. <GeometryModel3D>
  41.  
  42. <GeometryModel3D.Geometry>
  43. <MeshGeometry3D
  44. Positions="0.293893,-0.5,0.404509 0.475528,-0.5,0.154509 0,0.5,0 0.475528,-0.5,0.154509 0,0.5,0 0,0.5,0 0.475528,-0.5,0.154509 0.475528,-0.5,-0.154509 0,0.5,0 0.475528,-0.5,-0.154509 0,0.5,0 0,0.5,0 0.475528,-0.5,-0.154509
  45. 0.293893,-0.5,-0.404509 0,0.5,0 0.293893,-0.5,-0.404509 0,0.5,0 0,0.5,0 0.293893,-0.5,-0.404509 0,-0.5,-0.5 0,0.5,0 0,-0.5,-0.5 0,0.5,0 0,0.5,0 0,-0.5,-0.5 -0.293893,-0.5,-0.404509
  46. 0,0.5,0 -0.293893,-0.5,-0.404509 0,0.5,0 0,0.5,0 -0.293893,-0.5,-0.404509 -0.475528,-0.5,-0.154509 0,0.5,0 -0.475528,-0.5,-0.154509 0,0.5,0 0,0.5,0 -0.475528,-0.5,-0.154509 -0.475528,-0.5,0.154509 0,0.5,0
  47. -0.475528,-0.5,0.154509 0,0.5,0 0,0.5,0 -0.475528,-0.5,0.154509 -0.293892,-0.5,0.404509 0,0.5,0 -0.293892,-0.5,0.404509 0,0.5,0 0,0.5,0 -0.293892,-0.5,0.404509 0,-0.5,0.5 0,0.5,0 0,-0.5,0.5
  48. 0,0.5,0 0,0.5,0 0,-0.5,0.5 0.293893,-0.5,0.404509 0,0.5,0 0.293893,-0.5,0.404509 0,0.5,0 0,0.5,0"
  49. Normals="0.7236065,0.4472139,0.5257313 0.2763934,0.4472138,0.8506507 0.5308242,0.4294462,0.7306172 0.2763934,0.4472138,0.8506507 0,0.4294458,0.9030925 0.5308242,0.4294462,0.7306172 0.2763934,0.4472138,0.8506507 -0.2763934,0.4472138,0.8506507 0,0.4294458,0.9030925 -0.2763934,0.4472138,0.8506507 -0.5308242,0.4294462,0.7306172 0,0.4294458,0.9030925 -0.2763934,0.4472138,0.8506507
  50. -0.7236065,0.4472139,0.5257313 -0.5308242,0.4294462,0.7306172 -0.7236065,0.4472139,0.5257313 -0.858892,0.429446,0.279071 -0.5308242,0.4294462,0.7306172 -0.7236065,0.4472139,0.5257313 -0.8944269,0.4472139,0 -0.858892,0.429446,0.279071 -0.8944269,0.4472139,0 -0.858892,0.429446,-0.279071 -0.858892,0.429446,0.279071 -0.8944269,0.4472139,0 -0.7236065,0.4472139,-0.5257313
  51. -0.858892,0.429446,-0.279071 -0.7236065,0.4472139,-0.5257313 -0.5308242,0.4294462,-0.7306172 -0.858892,0.429446,-0.279071 -0.7236065,0.4472139,-0.5257313 -0.2763934,0.4472138,-0.8506507 -0.5308242,0.4294462,-0.7306172 -0.2763934,0.4472138,-0.8506507 0,0.4294458,-0.9030925 -0.5308242,0.4294462,-0.7306172 -0.2763934,0.4472138,-0.8506507 0.2763934,0.4472138,-0.8506507 0,0.4294458,-0.9030925
  52. 0.2763934,0.4472138,-0.8506507 0.5308249,0.4294459,-0.7306169 0,0.4294458,-0.9030925 0.2763934,0.4472138,-0.8506507 0.7236068,0.4472141,-0.5257306 0.5308249,0.4294459,-0.7306169 0.7236068,0.4472141,-0.5257306 0.8588922,0.4294461,-0.27907 0.5308249,0.4294459,-0.7306169 0.7236068,0.4472141,-0.5257306 0.8944269,0.4472139,0 0.8588922,0.4294461,-0.27907 0.8944269,0.4472139,0
  53. 0.858892,0.429446,0.279071 0.8588922,0.4294461,-0.27907 0.8944269,0.4472139,0 0.7236065,0.4472139,0.5257313 0.858892,0.429446,0.279071 0.7236065,0.4472139,0.5257313 0.5308242,0.4294462,0.7306172 0.858892,0.429446,0.279071" TriangleIndices="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 " />
  54. </GeometryModel3D.Geometry>
  55.  
  56. <GeometryModel3D.Material>
  57. <DiffuseMaterial>
  58. <DiffuseMaterial.Brush>
  59. <SolidColorBrush
  60. Color="Red"
  61. Opacity="1.0"/>
  62. </DiffuseMaterial.Brush>
  63. </DiffuseMaterial>
  64. </GeometryModel3D.Material>
  65.  
  66. </GeometryModel3D>
  67.  
  68. </Model3DGroup.Children>
  69. </Model3DGroup>
  70. </ModelVisual3D.Content>
  71. </ModelVisual3D>
  72. </ModelVisual3D.Children>
    //上面是Children,放模型
    //这里是Content,里面只放灯光
  73. <ModelVisual3D.Content>
  74. <Model3DGroup >
  75. <Model3DGroup.Children>
  76. <!-- Lights, MeshGeometry3D and DiffuseMaterial objects are added to the ModelVisual3D. -->
  77. <DirectionalLight Color="#FFFFFFFF" Direction="3,-4,5" />
  78.  
  79. <!-- Define a red cone. -->
  80. </Model3DGroup.Children>
  81. </Model3DGroup>
  82.  
  83. </ModelVisual3D.Content>
  84.  
  85. </ModelVisual3D>
  86.  
  87. </Viewport3D>
  88. </Grid>
  89.  
  90. </UserControl>

以上是我对wpf中最基础的三维的理解,如果错误,欢迎指出。

wpf——三维学习1的更多相关文章

  1. 【WPF】学习笔记(三)——这个家伙跟电子签名板有个约定

    这篇博客依旧是以电子签名板为基础而展开的,主要是对前文([WPF]学习笔记(一)--做一个简单的电子签名板)存在的部分问题进行解释,以及部分小功能的添加.由于这篇博客是建立在学习笔记一的基础上的,所以 ...

  2. WPF-学习笔记 动态修改控件Margin的值

    原文:WPF-学习笔记 动态修改控件Margin的值 举例说明:动态添加一个TextBox到Grid中,并设置它的Margin: TextBox text = new TextBox(); t_gri ...

  3. WPF三维图形

    原文:WPF三维图形 wpf 三维图形基础生成三维图形的基本思想是能得到一个物体的三维立体模型(model).由于我们的屏幕只有二维,因而我们定义了一个用于给物体拍照的照相机(Camera).拍到的照 ...

  4. WPF的学习笔记(1) -- (积累自2016年5月1日 至 2016年6月1日)

    敬告读者:因为是事件驱动模式的高速学习,高速学习意味着,不系统,不科学,不合逻辑,不一定正确.所以要是有不对的地方,页面下面留言给我,跪谢! 背景介绍: 最近在公司的开发工作中,接手了从别的公司交代过 ...

  5. WPF入门学习

    WPF基础知识 总结的学习WPF的几点基础知识: 1) C#基础语法知识(或者其他.NET支持的语言):这个是当然的了,虽然WPF是XAML配置的,但是总还是要写代码的,相信各位读者应该也都有这个基础 ...

  6. 《深入浅出WPF》 学习笔记

    <深入浅出WPF> 序言 1. 什么是WPF    2. 为什么要学习WPF 第一章 XAML概览 1. XAML是什么? 2. XAML有哪些优点 第二章 从零起步认识XAML 1. 新 ...

  7. wpf的学习日志(一)

    今天开始学习wpf,从xaml的布局开始 stackpanel布局:Orientation决定布局的横向还是纵向,HorizontalAlignment决定布局的对齐 <StackPanel O ...

  8. WPF项目学习.一

    WPF项目搭建 版权声明:本文为博主初学经验,未经博主允许不得转载. 一.前言 记录在学习与制作WPF过程中遇到的解决方案. 使用MVVM的优点是 数据和视图分离,双向绑定,低耦合,可重用行,相对独立 ...

  9. WPF项目学习.二

    WPF用MVVM的解决记录 版权声明:本文为博主初学经验,未经博主允许不得转载. 一.前言 记录在学习与制作WPF过程中遇到的解决方案.  焦点的控制,键盘事件触发,输入框的数字限制,异步处理,隐藏状 ...

随机推荐

  1. Android Automotive开发之一《编译自己的SDK 》 // TOBEDONE

    自己动手编译最新Android源码及SDK : http://blog.csdn.net/dd864140130/article/details/51718187官方文档,怎样编译sdk : http ...

  2. jq使用技巧

    1. 如何创建嵌套的过滤器 //允许你减少集合中的匹配元素的过滤器,  //只剩下那些与给定的选择器匹配的部分.在这种情况下,  //查询删除了任何没(:not)有(:has)  //包含class为 ...

  3. SpringMVC工作原理

    SpringMVC的工作原理图: SpringMVC流程 1.  用户发送请求至前端控制器DispatcherServlet. 2.  DispatcherServlet收到请求调用HandlerMa ...

  4. Rss 订阅:php动态生成xml格式的rss文件

    Rss 简介: 简易信息聚合(也 叫聚合内容)是一种描述和同步网站内容的格式.使用RSS订阅能更快地获取信息,网站提供RSS输出,有利于让用户获取网站内容的最新更新.网络用户可以在客户端借助于支持RS ...

  5. 在Unity中使用UGUI修改Mesh绘制几何图形

    在商店看到这样一个例子,表示很有兴趣,他们说是用UGUI做的.我想,像这种可以随便变形的图形,我第一个就想到了网格变形. 做法1: 细心的朋友应该会发现,每个UGUI可见元素,都有一个‘Canvas ...

  6. linux下如何关闭防火墙?如何查看防火墙当前的状态

    从配置菜单关闭防火墙是不起作用的,索性在安装的时候就不要装防火墙查看防火墙状态:/etc/init.d/iptables status暂时关闭防火墙:/etc/init.d/iptables stop ...

  7. Dom4J解析技术

    前面的话  本文主要讲解有关Dom4j技术和xpath配合下的优化!   目录:    为什么需要Dom4J    DOM4J怎么用    xpath怎么配合DOM4J 一  为什么需要Dom4J 一 ...

  8. 添加Silverlight应用到HTML

    Silverlight是跨浏览器,跨客户平台的浏览器插件,可以应用在Windows,Linux,Mac等平台.作为浏览器插件,Silverlight可以像Flash一样,很方便的嵌套在HTML页面中, ...

  9. 第3月第23天 EAIntroView

    1. EAIntroView,界面和模型分离.EAIntroPage数据模型,EAIntroView界面. https://github.com/ealeksandrov/EAIntroView

  10. 轻松搞定laravel的curd操作搞定简易留言版(四)

    一:目的开发laravel简易留言板 二:路由操作routes.php <?php //GET /msg/index 展示留言列表 //GET /msg/add 展示表单 //POST /msg ...