我在ViewPort3D中有一个2D广场,我想要对图像进行平铺(如棋盘或带有“瓷砖”效果的地板)。
我创建了一个图像画笔(图像为50x50像素,表面为250x550像素)和一个视口(试图跟随MS的网站 - 尽管他们的例子是2D),但“图块”图片中只有一种颜色显示没有看到平铺。
我在互联网上找不到一个例子,MS的网站上没有3D XAML上的任何信息(我可以找到),所以我很难理解如何实际做到这一点。
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="125,790,120" LookDirection="0,-.7,-0.25" UpDirection="0,0,1" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<AmbientLight Color="white" />
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="0,0,0 250,0,0 250,550,0 0,550,0 " TriangleIndices="0 1 3 1 2 3 "/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush ViewportUnits="Absolute" TileMode="Tile" ImageSource="testsquare.gif" Viewport="0,0,50,50" Stretch="None" ViewboxUnits="Absolute" />
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
答案 0 :(得分:3)
好的,明白了。除了TextureCoordinates,我还需要设置画笔的alignment属性。这是最终的工作代码。
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="125,790,120" LookDirection="0,-.7,-0.25" UpDirection="0,0,1" />
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<AmbientLight Color="white" />
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D Positions="0,0,0 250,0,0 250,550,0 0,550,0 " TriangleIndices="0 1 3 1 2 3" TextureCoordinates="0,0 250,0 250,550 0,550 "/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush ViewportUnits="Absolute" TileMode="Tile" ImageSource="testsquare.gif" Viewport="0,0,50,50" ViewboxUnits="Absolute" Stretch="None" AlignmentX="Left" AlignmentY="Top" />
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</GeometryModel3D.Material>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>