C#着色ImageBrush

时间:2017-08-03 10:34:05

标签: c# wpf 3d textures imagebrush

是否有可能改变画笔的色调。我目前正在使用画笔在wpf 3d中创建纹理材质。要获得选择和分组效果,每个模型最多需要三种材质。这导致了相当大的性能。这是当前的代码:

  DiffuseMaterial itemImageMaterial = new DiffuseMaterial(new ImageBrush(ItemTextures[nr]) { Stretch = Stretch.Fill });
  var meshGeom = new MeshGeometry3D();
  meshGeom.Positions = cubesPositions;
  meshGeom.TriangleIndices = cubesIndeces;
  GeometryModel3D geoMod = new GeometryModel3D();
  geoMod.Geometry = meshGeom;
  MaterialGroup mg = new MaterialGroup();
  mg.Children.Add(itemImageMaterial);
  if (applyGroupOverlay) mg.Children.Add(groupMaterials[groupNr]);
  if (applyHighlight) mg.Children.Add(highlightMaterials[highlightNr]);
  mg.Freeze();
  geoMod.Material = mg;
  (geoMod.Geometry as MeshGeometry3D).TextureCoordinates = cubesTextureCoords;
  Visual3DModel = geoMod;

NB。 ItemTextures [nr]是一个冻结的BitmapImage

希望有一个解决方案,以便代码看起来像这样:

  ImageBrush brush = new ImageBrush(ItemTextures[nr]) { Stretch = Stretch.Fill }
  if (applyGroupOverlay){
    //tint brush here
  }
  if (applyHighlight) {
    //tint brush some more here
  }
  DiffuseMaterial itemImageMaterial = new DiffuseMaterial(brush);
  var meshGeom = new MeshGeometry3D();
  meshGeom.Positions = cubesPositions;
  meshGeom.TriangleIndices = cubesIndeces;
  GeometryModel3D geoMod = new GeometryModel3D();
  geoMod.Geometry = meshGeom;
  geoMod.Material = itemImageMaterial;
  (geoMod.Geometry as MeshGeometry3D).TextureCoordinates = cubesTextureCoords;

这样,只需要一种材料就可以产生所需的效果。

0 个答案:

没有答案