Definition and illumination of WPF 3d:meshgeometry3d

Source: Internet
Author: User

Definition and illumination of the original WPF 3d:meshgeometry3d

Because WPF calculates the illumination based on the direction vectors of the entire plane, it may achieve different lighting effects if the same point is used on different faces. Let's illustrate this problem with a different way of defining mesh.

To define two simple intersecting polygons, the main view of the entire graph can be referenced as a convenience:

The first method is to use the simplest and most stupid method, one-time definition of all points, so that two polygons four triangles altogether 12 points, triangleindices is from 0 to 11.

The following code:

<meshgeometry3d positions= "-1 0 0, 0 0 1, 0 1 1,-1 0 0, 0 1 1,-1 1 0, 0 0 1, 1 0 0, 1 1 0, 0 0 1, 1 1 0, 0 1 1"
triangleindices= "0 1 2 3 4 5 6 7 8 9"/>

Results:

We have the desired effect.

It says, "because WPF calculates the light based on the direction vectors of the entire plane, if using the same point on different faces may achieve different lighting effects", then the next method, two polygons total 6 points, we only define these 6 points, reuse in triangleindices to see the results, Code:

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

Results:

Does not get the correct illumination in strict sense (using directionallight), because the vertices are reused, the illumination of the same plane is blended with different vertices to make the above effect.

Finally, the best way to do this is not to reuse vertices on different faces, but to reuse them on the same surface. In this way, two faces are fixed with 4 points, 8 points (between 112 points of the method and 26 points of the method).

This defines:

<meshgeometry3d positions= "-1 1 0, 0 1 1,-1 0-0, 0 0 1, 0 1 1, 1 1 0, 0 0 1, 1 0 0"
triangleindices= "2 1 0, 2 3 1, 6 5 4, 6 7 5"/>


You can achieve the same correct illumination as method one and define fewer points at the same time.

All code:

<Viewport3D>
<Viewport3D.Camera>
<perspectivecamera position= "0 0.5 3" lookdirection= "0 0-1"/>
</Viewport3D.Camera>
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup>
<directionallight direction= "1 0-2"
color= "White"/>
<GeometryModel3D>
<GeometryModel3D.Geometry>
<meshgeometry3d positions= "-1 1 0, 0 1 1,-1 0-0, 0 0 1, 0 1 1, 1 1 0, 0 0 1, 1 0 0"
triangleindices= "2 1 0, 2 3 1, 6 5 4, 6 7 5"/>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<diffusematerial brush= "Green"/>
</GeometryModel3D.Material>
</GeometryModel3D>
</Model3DGroup>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>

Definition and illumination of WPF 3d:meshgeometry3d

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.