WPF 3d:meshgeometry3d The correct definition of texture coordinates

Source: Internet
Author: User

The correct definition of the original WPF 3d:meshgeometry3d texture coordinates

To make 2D-based textures appear in 3D objects, we must define the texture mapping coordinates of the 3D mesh objects. In WPF, this feature is passed through the Meshgeometry3d.texturecoordinates property.

The corresponding coordinates of the LinearGradientBrush texture are the same as those of WPF's StartPoint and endpoint.

Notes from MSDN about LinearGradientBrush's startpoint:

(0,0) represents the upper-left corner of the entire graph, which represents the lower-right corner. (0,1) represents the lower left corner ... Of course units are relative, can use a decimal between 0 to 1 to represent the relative position of the middle.

For the simplest mesh definition without shared vertices (the meshgeometry3d.positions attribute has no share points), texturecoordinates corresponds to the coordinates of each triangle in the mesh, and of course this and meshgeometry3d.triangle The Indices property definition is related.

For example, define a simple 3D planar rectangle, first defining the Meshgeometry shell based on the triangle distribution. At this point, the texture coordinates to define the texture coordinates according to the location of the triangle, such as the first point is 0, 0, 0, obviously corresponds to the lower left corner of the rectangle in 3D space, then the first corresponding texturecoordinates is 0 1, and so on, so define the entire plane.

<meshgeometry3d positions= "0 0 0, 5 5 0, 0 5 0, 0 0 0, 5 0 0, 5 5 0"
triangleindices= "0 1 2 3 4 5"
texturecoordinates= "0 1, 1 0, 0 0,
0 1, 1 1, 1 0 "/>

The final texture is displayed correctly:

WPF 3d:meshgeometry3d The correct definition of texture coordinates

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.