WPF 3D - 复杂的几何形状映射渐变画笔 [英] WPF 3D - mapping gradient brush on complex geometry

查看:168
本文介绍了WPF 3D - 复杂的几何形状映射渐变画笔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问问是否有人知道如何映射渐变刷WPF中3D复杂对象。结果应类似于在MATLAB 3D图像(3D功能为例)。比方说你有一些你希望可视化的三维数据,并想通过颜色来diferentiate值的一定水平。

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.

推荐答案

给出一个GradientBrush定义是这样的:

Given a GradientBrush defined something like this:

        <LinearGradientBrush x:Name="RedYellowGradient">
            <GradientStop Color="Blue" Offset="0.01" />
            <GradientStop Color="Purple" Offset="0.25"/>
            <GradientStop Color="Red" Offset="0.5"/>
            <GradientStop Color="Orange" Offset="0.75"/>
            <GradientStop Color="Yellow" Offset="1.0"/>
        </LinearGradientBrush>

从根本上说,您分配 GradientBrush DiffuseMaterial MeshGeometry3D 。当定义画笔,将其 ViewportUnits 属性设置为绝对。

Fundamentally, you assign the GradientBrush to the DiffuseMaterial of your MeshGeometry3D. When defining the brush, set its ViewportUnits property to "Absolute".

像这样将直接在XAML形式的code-背后(使用相应的属性,否则,创建于code刷(在视图模型),或从资源字典称呼它)的工作

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):

MyMaterial = New DiffuseMaterial(RedYellowGradient) With {.ViewportUnits = BrushMappingMode.Absolute}

然后,对于每个三维点中的几何学,分配在0.0和1.0之间的值,以相应的纹理坐标。一般地,为pre尺寸数组也可能是这样的:

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:

    Parallel.For(0, positions.Count - 3, Sub(i)
                                             Dim p = positions(i)
                                             Dim plotValue = GetYourValue(p.X, p.Y, p.Z)
                                             Dim t = (plotValue - minPlot) / (maxPlot - minPlot)
                                             If t < 0 Then t = 0
                                             If t > 1 Then t = 1                                                
                                             arr(i) = New Point(t, 0.5)
                                         End Sub)

如果你的面很长,或顶点之间的价值相距甚远,你的计谋,看起来很奇怪。但考虑到WPF 3D的责难它可能是最好的,你没有很多的UV贴图可以做到。

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.

(如果你需要C#中,罗斯林CTP具有VS加载项,将在剪贴板转换VB code到C#...)

(If you need C#, the Roslyn CTP has a VS Add-on which will convert VB code on the clipboard to C#...)

这篇关于WPF 3D - 复杂的几何形状映射渐变画笔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆