在 Visual Studio 2017 中使用 3D Wavefront OBJ / STL

Posted

技术标签:

【中文标题】在 Visual Studio 2017 中使用 3D Wavefront OBJ / STL【英文标题】:Using 3D Wavefront OBJ / STL in Visual Studio 2017 【发布时间】:2018-07-26 08:13:40 【问题描述】:

我想将Wavefront OBJSTL 文件导入我的C# WPF 应用程序。

在较旧的帖子上是我不能再使用的演练。

Using 3D OBJ file in Blend 2015 https://social.msdn.microsoft.com/Forums/expression/en-US/06b6c4e4-def3-439d-9d0f-6f0fa5a14e8f/expression-blend-blend-for-visual-studio-obj-and-xaml?forum=wpf

是否不再可以“轻松”导入这些文件并在 VisualStudio / Blend 2017 中使用?


找到了HelixToolkit.WPF的教程,成功导入了一些文件:

https://www.codeproject.com/Tips/882885/Display-D-Model-using-Window-Presentation-Foundat

但这对我来说似乎不是完美的方式。我想做的是从SolidWorks 导出机器的一部分,将它们放入我的应用程序并创建我机器的 3d 可视化。

应该可以在designTime看到我的对象!

【问题讨论】:

【参考方案1】:

我使用Scichart WPF将一些Solidworks零件导入WPF,使用起来有点棘手,但你会得到你想要的,但是scichart不能制作动画,你只能有30天的试用期。 这是一个例子:

<s3D:SciChart3DSurface Name="sciChart3DSurface"
                   Grid.Column="1"
                   WorldDimensions="250,1,250">

<s3D:SciChart3DSurface.Resources>
    <!--  The 3D chess objects models which are used in this example were created by Fabio Valle, objects are used for  -->
    <!--  demonstrating purposes only to show possibility how to load and manipulate the 3D objects on 3D scene. Fabio's email: fabiovalle3d@gmail.com  -->
    <object:ObjectModelSource x:Key="PawnLowObj3DSource" Source="pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Objects/Pawn_Low.obj"/>
    <object:ObjectModelSource x:Key="BishopLowObj3DSource" Source="pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Objects/Bishop_Low.obj"/>
    <object:ObjectModelSource x:Key="KingLowObj3DSource" Source="pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Objects/King_Low.obj"/>
    <object:ObjectModelSource x:Key="KnightLowObj3DSource" Source="pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Objects/Knight_Low.obj"/>
    <object:ObjectModelSource x:Key="QueenLowObj3DSource" Source="pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Objects/Queen_Low.obj"/>
    <object:ObjectModelSource x:Key="RookLowObj3DSource" Source="pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Objects/Rook_Low.obj"/>
    <object:Rotation3D x:Key="ObjRotationState" Axis="YAxis" Angle="180" />
    <object:TextureSource x:Key="BlackTexture" Source="pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Objects/BlackWoodTexture.jpg" />
    <object:TextureSource x:Key="WhiteTexture" Source="pack://application:,,,/SciChart.Examples.ExternalDependencies;component/Resources/Objects/WhiteWoodTexture.jpg" />
</s3D:SciChart3DSurface.Resources>

<s3D:SciChart3DSurface.SceneObjects>
    <!--  The 3D chess objects models which are used in this example were created by Fabio Valle, objects are used for  -->
    <!--  demonstrating purposes only to show possibility how to load and manipulate the 3D objects on 3D scene. Fabio's email: fabiovalle3d@gmail.com  -->
    ...
    <object:ObjectModel3D TextureSource="StaticResource BlackTexture" Source="StaticResource RookLowObj3DSource" Position="0.0625, 0.6, 0.9375" CoordinateMode="Relative" Scale="0.2, 0.2, 0.2"/>
    <object:ObjectModel3D TextureSource="StaticResource BlackTexture" Source="StaticResource KnightLowObj3DSource" Position="0.0625, 0.6, 0.8125" CoordinateMode="Relative" Scale="0.2, 0.2, 0.2" Rotation="StaticResource ObjRotationState"/>
    <object:ObjectModel3D TextureSource="StaticResource BlackTexture" Source="StaticResource BishopLowObj3DSource" Position="0.4375, 0.6, 0.3125" CoordinateMode="Relative" Scale="0.2, 0.2, 0.2" Rotation="StaticResource ObjRotationState"/>
    <object:ObjectModel3D TextureSource="StaticResource BlackTexture" Source="StaticResource KingLowObj3DSource" Position="0.0625, 0.6, 0.5625" CoordinateMode="Relative" Scale="0.2, 0.2, 0.2"/>
    <object:ObjectModel3D TextureSource="StaticResource BlackTexture" Source="StaticResource QueenLowObj3DSource" Position="0.0625, 0.6, 0.4375" CoordinateMode="Relative" Scale="0.2, 0.2, 0.2" Rotation="StaticResource ObjRotationState"/>
    <object:ObjectModel3D TextureSource="StaticResource BlackTexture" Source="StaticResource BishopLowObj3DSource" Position="0.0625, 0.6, 0.3125" CoordinateMode="Relative" Scale="0.2, 0.2, 0.2" Rotation="StaticResource ObjRotationState"/>
    <object:ObjectModel3D DrawBoundingBox="True" BoundingBoxStroke="White" TextureSource="StaticResource BlackTexture" Source="StaticResource KnightLowObj3DSource" Position="0.3125, 0.6, 0.3125" CoordinateMode="Relative" Scale="0.2, 0.2, 0.2" Rotation="StaticResource ObjRotationState"/>
    <object:ObjectModel3D TextureSource="StaticResource BlackTexture" Source="StaticResource RookLowObj3DSource" Position="0.0625, 0.6, 0.0625" CoordinateMode="Relative" Scale="0.2, 0.2, 0.2"/>
    ...
</s3D:SciChart3DSurface.SceneObjects>

这是一张演示图片:

【讨论】:

以上是关于在 Visual Studio 2017 中使用 3D Wavefront OBJ / STL的主要内容,如果未能解决你的问题,请参考以下文章

如何使用Visual Studio 2013或Visual Studio 2017设置TFS 2013

在 Visual Studio 2017 中使用 64 位 Visual C++ 工具集

如何在 Visual Studio 2017 中使用 Qt 库?

在 Visual Studio 2017 中使用 CUDA

Visual Studio 2017工程在Visual Studio 2019打开碰到的问题

Visual Studio 2017工程在Visual Studio 2019打开碰到的问题