简体   繁体   English

在WPF 3D中使用纹理

[英]Using textures in wpf 3D

I got a question about using textures in WPF on 3D models. 我有一个关于在3D模型中的WPF中使用纹理的问题。 this is my first time in WPF 3D. 这是我第一次使用WPF 3D。

It did succeed doing it (kinda) the same way for the floor plane. 它确实成功地(针对地板)以相同的方式进行了这种操作。 It works to get the texture on the model that represent the 4 outside walls but its completly streched and/or it's displayed crooked as seen on the following image. 它可以在代表4个外墙的模型上获取纹理,但是其完全拉长和/或显示为弯曲,如下图所示。

质地问题

I think the problem is that the model has more then 4 points, It has 8 to be exact and 4 planes constructed out of 2 triangles each. 我认为问题在于模型有4个以上的点,确切地说有8个点,每个平面由2个三角形构成4个平面。

I dont really know what I'm doing wrong. 我真的不知道我在做什么错。 It probably has something to do with the texture coordinates but I cant figure out what. 它可能与纹理坐标有关,但我不知道是什么。 Already tried some other values on the texture coordinates but that did not help much. 已经在纹理坐标上尝试了其他一些值,但是并没有太大帮助。

It would be great if someone could help me figure this out or atleast point me in the right direction. 如果有人可以帮助我解决这个问题,或者至少将我指向正确的方向,那就太好了。

my XAML code of the model: 我的模型的XAML代码:

<GeometryModel3D>
    <GeometryModel3D.Geometry>
        <MeshGeometry3D Positions="20,0,0 20,0,3 20,20,3 20,20,0 0,20,3 0,0,0  0,20,0 0,0,3"
        TriangleIndices="0 1 2 3 0 2    4 5 6 4 7 5    0 5 1 1 5 7   6 3 4 4 3 2"
        TextureCoordinates="0,0 0,1 1,0 1,1    0,0 0,1 1,0 1,1    0,1 0,1 1,0 1,1   0,0 0,1 1,0 1,1"/>
     </GeometryModel3D.Geometry>
     <GeometryModel3D.Material>
         <DiffuseMaterial>
             <DiffuseMaterial.Brush>
                 <ImageBrush ImageSource="pack://siteoforigin:,,,/images/brick.jpg" />
             </DiffuseMaterial.Brush>
         </DiffuseMaterial>
      </GeometryModel3D.Material>
         <GeometryModel3D.BackMaterial>
         <DiffuseMaterial>
            <DiffuseMaterial.Brush>
               <SolidColorBrush Color="Blue"/>
            </DiffuseMaterial.Brush>
         </DiffuseMaterial>
      </GeometryModel3D.BackMaterial>
 </GeometryModel3D>

I fixed it myself. 我自己修好了。 Instead of re-using the same point for multiple vertices, I re-created the point. 我没有为多个顶点重复使用同一点,而是重新创建了该点。 Now I have a few more points but it works to put the texture decent on every rectangle. 现在,我还有一些要点,但是它可以使每个矩形上的纹理都像样。

example how i used to do it: 我以前如何做的例子:

points: 0,0,0    0,0,1    1,0,0    1,0,1      0,1,0     0,1,1

indices: 0 2 1   2 3 1   0 1 4   1 4 3

texture coordinates: 0,1 0,0 1,1 1,0 1,1 1,0

example how i fixed:

points: 0,0,0    0,0,1    1,0,0    1,0,1    0,0,0    0,0,1    0,1,0     0,1,1

indices: 0 2 1   2 3 1    4 5 6   7 6 4

texture coordinates: 0,1 0,0 1,1 1,0    1,1 1,0  0,1 0,0

this isnt probably the most efficient/best sollution but it is a solution and it worked for me. 这可能不是最有效/最佳的解决方案,但这是一个解决方案,对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM