当前位置:网站首页>WPF 三维应用搭建(基础)
WPF 三维应用搭建(基础)
2022-07-17 06:43:00 【执着的涛】
1 创建项目
选择创建WPF应用

给程序起一个酷酷的名字,选一个酷酷的位置:

选一下.NET6

2 配置项目
从nuget.org上安装AnyCAD Rapid SDK 2022。

3 设计界面
- 首先引入程序集:
xmlns:anycad="clr-namespace:AnyCAD.WPF;assembly=AnyCAD.WPF.NET6"
- 设计布局
给三维界面留个位置,采用经典的左右窗口。右边用来显示三维内容。完整的xaml如下:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
xmlns:anycad="clr-namespace:AnyCAD.WPF;assembly=AnyCAD.WPF.NET6"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100" Width="0.3*"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<anycad:RenderControl Grid.Column="1" x:Name="mRenderCtrl"/>
</Grid>
</Window>运行一下:

5 显示模型
- 增加一个ViewerReady事件

<anycad:RenderControl Grid.Column="1" x:Name="mRenderCtrl" ViewerReady="mRenderCtrl_ViewerReady"/>- 在mRenderCtrl_ViewerReady中创建一个球
private void mRenderCtrl_ViewerReady()
{
var shape = ShapeBuilder.MakeSphere(new GPnt(0, 0, 0), 100);
mRenderCtrl.ShowShape(shape, ColorTable.AliceBlue);
}在三维控件初始化完成之前是不能进行对控件进行操作的
再运行一下:

6 资源释放
在调试模式下,程序退出的时候在输出窗口中,你可能会发现这样的错误:
程序“[57196] WpfApp1.exe”已退出,返回值为 3221225477 (0xc0000005) 'Access violation'。
这是因为AnyCAD Rapid SDK没有正确的释放资源。为保证三维控件资源能够正确释放,程序能够得到正常的返回值,只需要这样加一下Startup和Exit消息:
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml" Exit="Application_Exit" Startup="Application_Startup">
<Application.Resources>
</Application.Resources>
</Application>代码修改:
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
AnyCAD.Foundation.GlobalInstance.Initialize();
}
private void Application_Exit(object sender, ExitEventArgs e)
{
AnyCAD.Foundation.GlobalInstance.Destroy();
}
}边栏推荐
- If a number in C language is exactly equal to the sum of its factors, this number is called "perfect". For example, 6=1 + 2 + 3 programming
- redis缓存雪崩、穿透、击穿
- 三伏天逛逛北京动物园
- redis分布式锁
- How to check whether the app has user information and data leakage vulnerabilities
- V8 引擎如何进行垃圾内存的回收?
- redis6新功能
- 面试题:外边距折叠问题 (块级元素在普通文档流中的BUG)
- Transferring multiple pictures is the judgment of empty situation.
- Modify radio style
猜你喜欢

【JVM】之虚拟机栈

Shenzhen Prudential written examination record

Understand LSTM and Gru

From the casino logic, analyze the investment value of platform currency 2020-03-03

Using PCA to simplify data

Redis jump table implementation principle & time complexity analysis

Double index mechanism of redis source code analysis

Wechat oauth2.0 login process and security analysis
![[MySQL] lock mechanism: detailed explanation of lock classification, table lock, row lock and page lock in InnoDB engine](/img/7e/ddf05e76da26e9b2d1fd1519703571.png)
[MySQL] lock mechanism: detailed explanation of lock classification, table lock, row lock and page lock in InnoDB engine

Redis 跳跃表实现原理 & 时间复杂度分析
随机推荐
力扣114题:二叉树展开链表
Download, installation and use of mongodb
csp-2020-6-《角色授权》
redis 存储结构原理 2
STM32F103C8T6硬件IIC控制4针0.96寸OLED显示屏
网站漏洞修复服务商分析可控参数带来的越权
半导体材料技术
“韭菜”是怎么把钱送给“镰刀”的? 2020-03-07
redis6新功能
redis缓存雪崩、穿透、击穿
Use of fiddler packet capturing tool
三伏天逛逛北京动物园
cad填充转多段线脚本
Machine learning interview questions (Reprinted)
Conversation technology [dark horse introduction series]
【MySQL】 事务:事务基础知识、MySQL事务实现原理、事务日志 redolog & undolog 详解
[C# 类和对象]-C# 中的方法以及类和对象编程
Visual Studio 生产环境配置方案:SlowCheetah
《牛客刷题》sql错题集
By voting for the destruction of STI by Dao, seektiger is truly community driven
