当前位置:   article > 正文

WPF UI 3D 多轴 机械臂 stl 模型UI交互_wpf 三维机械设备展示

wpf 三维机械设备展示


 

1、三维插件环境调整
2、动态模型材质处理
3、动态模型鼠标交互
4、模型旋转基本思路
5、六轴机械臂节点旋转处理
6、更多HelixToolkit插件处理案例
7、快速对接Blender模型

鼠标交互(没有强调场景的变换)
鼠标命中测试(HitTest   不推荐)
平面对象加载

数据绑定(数据与动作)   

环境配置与相关方法  
模型准备:Blender/SolidWorks
模型导入
HelixToolkit更多案例

WPF UI 3D 多轴 机械臂 stl 模型UI交互

顶部控件多轴控制

ui

  1. <StackPanel VerticalAlignment="Top">
  2. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="1"/>
  3. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="2"/>
  4. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="3"/>
  5. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="8"/>
  6. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="9"/>
  7. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="10"/>
  8. </StackPanel>

ui后端

  1. private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  2. {
  3. int index = int.Parse((sender as Slider).Tag.ToString());
  4. (((models[index].Transform as Transform3DGroup).Children[1] as RotateTransform3D)
  5. .Rotation as AxisAngleRotation3D).Angle = e.NewValue;
  6. }

效果

2

3

4

5

多轴材质控制

ui

  1. <h:HelixViewport3D Name="hv"
  2. ShowViewCube="True"
  3. ViewCubeWidth="100"
  4. ViewCubeHeight="100"
  5. ViewCubeHorizontalPosition="Left"
  6. ViewCubeVerticalPosition="Top"
  7. ViewCubeFrontText="前"
  8. ViewCubeTopText="上"
  9. ShowCoordinateSystem="True"
  10. CoordinateSystemLabelForeground="#5000"
  11. CoordinateSystemHorizontalPosition="Left"
  12. CoordinateSystemVerticalPosition="Bottom"
  13. RotateAroundMouseDownPoint="True"
  14. MouseLeftButtonDown="HelixViewport3D_MouseLeftButtonDown" Margin="0,0,-344,-320"
  15. >
  16. <!--========================HelixViewport3D对象的属性(必须在内容之前)==========================-->
  17. <h:HelixViewport3D.Background>
  18. <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
  19. <GradientStop Color="#556" Offset="0"/>
  20. <GradientStop Color="#FF1D64FF" Offset="1"/>
  21. </LinearGradientBrush>
  22. </h:HelixViewport3D.Background>
  23. <!--相机-->
  24. <h:HelixViewport3D.Camera>
  25. <PerspectiveCamera Position="-1571, 4801, 3774"
  26. LookDirection="2038, -5200, -2930"
  27. FieldOfView="50"
  28. UpDirection="-0.145, 0.372, 0.917"
  29. FarPlaneDistance="10000"
  30. NearPlaneDistance="1"/>
  31. </h:HelixViewport3D.Camera>
  32. <h:HelixViewport3D.RotateGesture>
  33. <MouseGesture MouseAction="LeftClick"/>
  34. </h:HelixViewport3D.RotateGesture>
  35. <h:HelixViewport3D.PanGesture>
  36. <MouseGesture MouseAction="RightClick"/>
  37. </h:HelixViewport3D.PanGesture>
  38. <!--========================HelixViewport3D对象的属性(结束)==========================-->
  39. <!--========================HelixViewport3D对象的内容(必须在属性配置之后)==========================-->
  40. <!--光源-->
  41. <!--<ModelVisual3D>
  42. <ModelVisual3D.Content>
  43. <Model3DGroup>
  44. <AmbientLight Color="White"/>
  45. </Model3DGroup>
  46. </ModelVisual3D.Content>
  47. </ModelVisual3D>-->
  48. <h:DefaultLights/>
  49. <!--网格线-->
  50. <h:GridLinesVisual3D Width="16000" Length="16000" Thickness="1"
  51. Fill="#EEE" MinorDistance="100" MajorDistance="400"/>
  52. <!--模型-->
  53. <!--<ModelVisual3D x:Name="model">
  54. <ModelVisual3D.Content>
  55. <Model3DGroup>
  56. <GeometryModel3D>
  57. C#加载的一个stl模型文件
  58. </GeometryModel3D>
  59. <GeometryModel3D>
  60. C#加载的一个stl模型文件
  61. </GeometryModel3D>
  62. <GeometryModel3D>
  63. C#加载的一个stl模型文件
  64. </GeometryModel3D>
  65. </Model3DGroup>
  66. </ModelVisual3D.Content>
  67. </ModelVisual3D>-->
  68. <!--<ModelUIElement3D MouseLeftButtonDown="">
  69. <ModelUIElement3D.Model>
  70. <GeometryModel3D>
  71. C#加载的一个stl模型文件
  72. </GeometryModel3D>
  73. </ModelUIElement3D.Model>
  74. </ModelUIElement3D>-->
  75. <!--<ModelUIElement3D MouseLeftButtonDown="">
  76. <ModelUIElement3D.Model>
  77. <GeometryModel3D>
  78. C#加载的一个stl模型文件
  79. </GeometryModel3D>
  80. </ModelUIElement3D.Model>
  81. </ModelUIElement3D>-->
  82. <!--<ModelUIElement3D MouseLeftButtonDown="">
  83. <ModelUIElement3D.Model>
  84. <GeometryModel3D>
  85. C#加载的一个stl模型文件
  86. </GeometryModel3D>
  87. </ModelUIElement3D.Model>
  88. </ModelUIElement3D>-->
  89. <!--========================HelixViewport3D对象的内容(结束)==========================-->
  90. </h:HelixViewport3D>
  91. <StackPanel VerticalAlignment="Top">
  92. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="1"/>
  93. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="2"/>
  94. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="3"/>
  95. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="8"/>
  96. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="9"/>
  97. <Slider Minimum="0" Maximum="360" Value="0" ValueChanged="Slider_ValueChanged" Tag="10"/>
  98. </StackPanel>
  1. /*stl文件*/
  2. string[] model_files = System.IO.Directory.GetFiles($"{Environment.CurrentDirectory}/3D_Models");
  3. ModelImporter importer = new ModelImporter();
  4. //Model3DGroup group = new Model3DGroup();
  5. foreach (var file in model_files)
  6. {
  7. ModelUIElement3D mui = new ModelUIElement3D();
  8. // 关键的模型文件解析过程=》 GemotryModel3D
  9. var mg = importer.Load(file);
  10. var geo = mg.Children[0] as GeometryModel3D;
  11. geo.Material = NormalMaterial(Brushes.White);
  12. geo.BackMaterial = NormalMaterial(Brushes.White);
  13. mui.Model = geo;
  14. // 这里想办法添加鼠标动作
  15. //mui.MouseLeftButtonDown += (a, b) =>
  16. //{
  17. // geo.Material = NormalMaterial(Brushes.Green);
  18. // geo.BackMaterial = NormalMaterial(Brushes.Green);
  19. //};
  20. mui.MouseLeftButtonDown += Mui_MouseLeftButtonDown;
  21. //if (file.IndexOf("LINK1_CAD") > -1)
  22. //{
  23. // RotateTransform3D rt = new RotateTransform3D();
  24. // rt.Rotation = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0);
  25. // rt.CenterX = 0;
  26. // rt.CenterY = 0;
  27. // rt.CenterZ = 0;
  28. // mui.Transform = rt;
  29. // currentMUI = mui;
  30. //}
  31. this.hv.Children.Add(mui);
  32. models.Add(mui);
  33. }
  34. //this.model.Content = group;
  35. SetTransform();

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/804282
推荐阅读
相关标签
  

闽ICP备14008679号