Wpf中用HelixToolkit轻松加载SolidWorks导出3D模型

时隔多年,HelixToolkit.SharpDX真的加强不少,得益于assimp-net这个项目,HelixToolkit可以加载各种模型并播放动画,下面就来看看HelixToolkit如何与SolidWorks碰撞出火花

 

一、加载SolidWorks导出的XAML来显示模型

 

我们在SolidWorks工程内,另存为XAML格式,我就不贴全了

 

<Viewport3D>
    <Viewport3D.Camera>
        <OrthographicCamera Position="1.186027,1.102421,1.711027" LookDirection="-0.577382,-0.577288,-0.577382" UpDirection="-0.408204,0.816541,-0.408204" NearPlaneDistance="1.027074" FarPlaneDistance="3.081221" Width="2.054147"/>
    Viewport3D.Camera>
    <Viewport3D.Children>
        <ModelVisual3D>
            <ModelVisual3D.Transform>
                <RotateTransform3D>
                    <RotateTransform3D.Rotation>
                        <AxisAngleRotation3D Angle="0" Axis="0,1,0"/>
                    RotateTransform3D.Rotation>
                RotateTransform3D>
            ModelVisual3D.Transform>
            <ModelVisual3D.Children>
                <ModelVisual3D>
                    <ModelVisual3D.Content>
                        <Model3DGroup>
                            <Model3DGroup.Children>
                                <AmbientLight Color="#262626"/>
                                <DirectionalLight Color="#6F6F6F" Direction="3.150000,-8.090000,-4.960000"/>
                                <DirectionalLight Color="#454545" Direction="8.610000,4.820000,-1.640000"/>
                                <DirectionalLight Color="#332835" Direction="-9.490000,3.090000,0.600000"/>
                                <DirectionalLight Color="#151515" Direction="-5.500000,-8.300000,-1.100000"/>
                            Model3DGroup.Children>
                        Model3DGroup>
                    ModelVisual3D.Content>
                ModelVisual3D>
                <ModelVisual3D>
                    <ModelVisual3D.Transform>
                        <MatrixTransform3D Matrix="1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 "/>
                    ModelVisual3D.Transform>
                    <ModelVisual3D.Content>
                        <Model3DGroup>
                            <Model3DGroup.Children>
                                <GeometryModel3D>
                                    <GeometryModel3D.Material>
                                        <MaterialGroup>
                                            <DiffuseMaterial>
                                                <DiffuseMaterial.Brush>
                                                    <SolidColorBrush Color="#C6C1BC" Opacity="1.000000"/>
                                                DiffuseMaterial.Brush>
                                            DiffuseMaterial>
                                            <SpecularMaterial SpecularPower="0.700000">
                                                <SpecularMaterial.Brush>
                                                    <SolidColorBrush Color="#8A8783" Opacity="1.000000"/>
                                                SpecularMaterial.Brush>
                                            SpecularMaterial>
                                        MaterialGroup>
                                    GeometryModel3D.Material>
                                    <GeometryModel3D.Geometry>
                                        <MeshGeometry3D Positions="-0.182068,0.380704,0.052289 -0.223695,0.357833,0.000000 -0.178693,0.382299,0.051022 -0.171721,0.385481,0.000000 -0.171721,0.385481"/>
                                    GeometryModel3D.Geometry>

 

把它放到自己的wpf里面去,这个时候可以用代码随意的控制里面的元素了,但是操作不是很方便,能不能搞个旋转缩放的默认操作呢? 这时候就用到HelixToolkit.Wpf了,

我们把ModelVisual3D节点,放到HelixToolkit的控件节点中,便可以进行鼠标操作

 

 Wpf中用HelixToolkit轻松加载SolidWorks导出3D模型_第1张图片

 

 导出xaml不能导出太复杂的东西,因为所有格式里,xaml是最大的,贴到VS里去搞不好要崩溃

 

二、使用HelixToolkit.SharpDX加载SolidWorks导出的3mf

solidworks导出的格式里都比较奇葩,没有常见的.x .obj .fbx,剩下的格式里最通用的就是这个3mf格式了,这个格式就比xaml强多了

我们可以使用HelixToolkit.SharpDX工程里的FileLoadDemo去加载他看看

 

Wpf中用HelixToolkit轻松加载SolidWorks导出3D模型_第2张图片

 

 

HelixToolkit.SharpDX会拥有更好的光照,更多的特性,潜力更大,性能更好。

大家自己也可以用普通的3dsmax,maya导出点常规格式玩玩,还支持fbx动画哦。

你可能感兴趣的:(Wpf中用HelixToolkit轻松加载SolidWorks导出3D模型)