我使用VS 2008 C#Express。 我想在包含很多3D对象的窗口中更改3D对象的不透明度值。 更改过程将由代码隐藏完成。如何更改3D对象的不透明度值
你能解释一下它是如何完成的。
感谢
B.Joe
我使用VS 2008 C#Express。 我想在包含很多3D对象的窗口中更改3D对象的不透明度值。 更改过程将由代码隐藏完成。如何更改3D对象的不透明度值
你能解释一下它是如何完成的。
感谢
B.Joe
你可以操纵材料的不透明性在它包含刷的条款。
这是正确的想法。您必须确保操作Material和BackMaterial,并处理更新实际材料。我添加了一个显示如何执行此操作的答案。 – 2010-06-04 23:04:29
假设你的3D对象是内ModelVisual3D
或ModelUIElement3D
一个Model3DGroup
或GeometryModel3D
,改变不透明度为在它遍历各个GeometryModel3D
S和更新每个人的Material
和BackMaterial
,东西沿着这些路线的问题:
public void SetOpacity(Model3D model, double opacity)
{
var modelGroup = model as Model3DGroup;
var geoModel = model as GeometryModel3D;
if(modelGroup!=null)
foreach(var submodel in modelGroup.Children)
SetOpacity(submodel, opacity);
if(geoModel!=null)
{
geoModel.Material = SetOpacity(geoModel.Material, opacity);
geoModel.BackMaterial = SetOpacity(geoModel.BackMaterial, opacity);
}
}
public Brush SetOpacity(Brush brush, double opacity)
{
if(!GetIsOpacityControlBrush(brush)) // Use attached property to mark brush
{
brush = new VisualBrush
{
Visual = new Rectangle { Fill = brush, ... };
};
SetIsOpacityControlBrush(brush, true);
}
((Rectangle)((VisualBrush)brush).Visual).Opacity = opacity;
}
您将需要遍历对象中的所有GeometryModel3D和ViewPort2DVisual3D。对于每个GeometryModel3D,将材质更新为新的不透明度,如有必要,使用VisualBrush。对于每个ViewPort2DVisual3D,只需设置不透明度
如果你的3D对象是的Visual3D如ContainerUIElement3D,那么你必须先迭代细分到个人ModelVisual3D和ModelUIElement3D去,包括它的模型。此外,如果您遇到ViewPort2DVisual3D,则可以直接在包含的Visual上设置不透明度。
您使用的是WPF吗? 3D对象究竟是什么? – SLaks 2010-02-23 21:47:33
另外,您可以发布描述您试图使对象不透明的代码吗?我想像一下3D对象本身可能存在一个“不透明”属性。 – CrimsonX 2010-02-23 21:57:50