如预期的Viewport2DVisual3D,但不是一个GeometryModel3D为什么TextureCoordinates工作? [英] Why does TextureCoordinates work as expected for a Viewport2DVisual3D, but not for a GeometryModel3D?

查看:376
本文介绍了如预期的Viewport2DVisual3D,但不是一个GeometryModel3D为什么TextureCoordinates工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我在3ds Max中创建的模型。该模型是一个简单的矩形。其质地有重叠的纹理坐标 - 该模型应该显示的图像文件的右半两次,并排侧。我出口这种模式为 .OBJ ,并使用微软前pression混合将其转换为XAML。

I have a model that I created in 3ds Max. The model is a simple rectangle. Its texture has overlapping texture coordinates--the model should display the right half of the image file twice, side-by-side. I exported this model as an .obj, and converted it to XAML using Microsoft Expression Blend.

我把 MeshGeometry3D 的融合,并把它添加到 Viewport3D 使用以下两种方法:

I took the MeshGeometry3D from blend, and added it to a Viewport3D using two methods:

  1. 使用一个 Viewport2DVisual3D 标签视觉。在标签的背景设置为纹理图像。使用这种方法,一切都按预期工作。
  2. 使用一个 ModelVisual3D GeometryModel3D 内容。在 GeometryModel3D 的材料设置为 DiffuseMaterial 使用图像作为其画笔。使用这种方法, TextureCoordinates MeshGeometry3D 似乎是跨preTED不同。
  1. Use a Viewport2DVisual3D with a Label as its Visual. Set the Label's background to the texture image. Using this method, everything works as expected.
  2. Use a ModelVisual3D with a GeometryModel3D as its Content. Set the GeometryModel3D's material to a DiffuseMaterial that uses the image as its brush. Using this method, the TextureCoordinates of the MeshGeometry3D appear to be interpreted differently.

的完整code为如下。在code-后面是空的,除了的InitializeComponent()

The full code is provided below. The code-behind is empty except for InitializeComponent():

<Window x:Class="TestTextureCoordinates.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <Grid.Resources>
        <MeshGeometry3D x:Key="geometry"
                        Normals="0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1 0,0,1"
                        Positions="113.8997,102.4171,0 148.9045,102.4171,0 148.9045,148.41161,0 113.8997,148.41161,0 184.5722,102.4171,0 184.5722,148.41161,0 148.9045,148.41161,0 148.9045,102.4171,0"
                        TextureCoordinates="0.50639999,0.9995 1.0065,0.9995 1.0065,0.00050002337 0.50639999,0.00050002337 1.0022,0.9995 1.0022,0.00050002337 0.5,0.00050002337 0.5,0.9995"
                        TriangleIndices="0 1 2 0 2 3 4 5 6 4 6 7"/>
        <ImageBrush x:Key="brush" ImageSource="img/test.jpg" />
    </Grid.Resources>

    <Viewport3D>
        <Viewport3D.Camera>
            <PerspectiveCamera Position="195,125,210" LookDirection="0,0,-1" />
        </Viewport3D.Camera>

        <ModelVisual3D>
            <ModelVisual3D.Content>
                <AmbientLight Color="White" />
            </ModelVisual3D.Content>
        </ModelVisual3D>

        <!-- The first model, using a Viewport2DVisual3D. This works as intended. -->
        <Viewport2DVisual3D Geometry="{StaticResource geometry}">
            <Viewport2DVisual3D.Visual>
                <Label Background="{StaticResource brush}" />
            </Viewport2DVisual3D.Visual>
            <Viewport2DVisual3D.Material>
                <DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" />
            </Viewport2DVisual3D.Material>
        </Viewport2DVisual3D>

        <!-- The second model, using a ModelVisual3D and GeometryModel3D. The TextureCoordinates do not work as intended. -->
        <ModelVisual3D>
            <!-- We apply a transform to offset this model from the first model. -->
            <ModelVisual3D.Transform>
                <TranslateTransform3D OffsetX="90" />
            </ModelVisual3D.Transform>
            <ModelVisual3D.Content>
                <GeometryModel3D Geometry="{StaticResource geometry}">
                    <GeometryModel3D.Material>
                        <DiffuseMaterial Brush="{StaticResource brush}" />
                    </GeometryModel3D.Material>
                </GeometryModel3D>
            </ModelVisual3D.Content>
        </ModelVisual3D>
    </Viewport3D>
</Grid>

下面是 test.jpg放在

下面是最终结果。左边是 Viewport2DVisual3D ,因为它在3ds Max中看起来是一样的。在右边的是 ModelVisual3D ,这似乎是除preting的 TextureCoordinates 是不同的。

Here is the final result. On the left is the Viewport2DVisual3D, which looks the same as it does in 3ds Max. On the right is the ModelVisual3D, which appears to be interpreting the TextureCoordinates differently.

这是怎么回事呢?由于该软件的其他要求我的工作,我不能使用 Viewport2DVisual3D 。我怎样才能让一个 GeometryModel3D 除preT的 TextureCoordinates 是否正确?

What's going on here? Due to other requirements of the software I am working on, I cannot use a Viewport2DVisual3D. How can I make a GeometryModel3D interpret the TextureCoordinates correctly?

推荐答案

我不得不设置 ViewportUnits 的ImageBrush 绝对

<ImageBrush x:Key="brush" ImageSource="img/test.jpg" ViewportUnits="Absolute" />

请参阅这个帖子从WPF3D团队博客:

See this post from the WPF3D team blog:

如果您没有设置TileBrush.ViewportUnits为BrushMappingMode.Absolute,纹理坐标将是相对于你的几何形状的边框。例如,假设你只需要一半的v您的纹理映射到网格。在其他的API,你只需范围从0.0的坐标 - > 0.5。如果你这样做,在WPF3D没有设置ViewportUnits以绝对的,它仍然会映射整个事情。基本上任何你不想整个纹理的一个副本时,你会想设置绝对。

If you don't set TileBrush.ViewportUnits to BrushMappingMode.Absolute, your texture coordinates will be relative to the bounding box of your geometry. For example, let's say you only want half of your texture in v to be mapped to the mesh. In other APIs, you would just range your coordinate from 0.0 -> 0.5. If you do that in WPF3D without setting ViewportUnits to Absolute, it'll still map the entire thing. Essentially any time you don't want one copy of the entire texture you'll want to set Absolute.

这篇关于如预期的Viewport2DVisual3D,但不是一个GeometryModel3D为什么TextureCoordinates工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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