WPF 3D - 在复杂几何体上映射渐变画笔
我想问是否有人知道如何在 WPF 3D 中的复杂对象上映射渐变画笔。结果应该类似于 matlab 中的 3D 图像(例如 3D 函数)。假设您有一些想要可视化的 3 维数据,并且想要通过颜色区分某些级别的值。
I wanted to ask if anyone knows how to map gradient brush on complex objects in WPF 3D. The result should look similar to 3D images in matlab (3D function for example). Lets say you have some 3-dimensional data you wish to visualize and you want to diferentiate certain levels of values by color.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定一个 GradientBrush 定义如下:
从根本上讲,您将
GradientBrush
分配给MeshGeometry3D
的DiffuseMaterial
。定义画笔时,将其ViewportUnits
属性设置为“Absolute”。类似这样的东西可以直接在 XAML 表单的代码隐藏中工作(否则,使用相应的属性在代码中(在 ViewModel 中)创建画笔,或从资源字典中调用它):
然后,对于几何图形中的每个 Point3D ,将 0.0 到 1.0 之间的值分配给相应的纹理坐标。一般来说,对于预先确定大小的点数组,它可能如下所示:
如果面很长或者顶点之间的值相距很远,则绘图看起来会很奇怪。但考虑到 WPF 3D 的限制,这可能是无需大量 UV 贴图即可实现的最佳选择。
(如果您需要 C#,Roslyn CTP 有一个 VS 插件,可以将剪贴板上的 VB 代码转换为 C#...)
Given a GradientBrush defined something like this:
Fundamentally, you assign the
GradientBrush
to theDiffuseMaterial
of yourMeshGeometry3D
. When defining the brush, set itsViewportUnits
property to "Absolute".Something like this would work directly in the code-behind of a XAML form (otherwise, create the brush in code (in your ViewModel) using the corresponding properties, or call it from your resource dictionary):
Then, for each Point3D in your geometry, assign a value between 0.0 and 1.0 to the corresponding texture coordinate. Generically, for a pre-sized
Point
array it could look like this:If your facets are very long or the values between vertices very far apart, your plotting will look odd. But given the strictures of WPF 3D it's probably the best you can do without a lot of UV Mapping.
(If you need C#, the Roslyn CTP has a VS Add-on which will convert VB code on the clipboard to C#...)