WPF 3D knowledge points and examples, wpf3d knowledge points

Source: Internet
Author: User
Tags in degrees

WPF 3D knowledge points and examples, wpf3d knowledge points
Introduction

The reason is that a triangle is used to describe the most subtle ry of a plane. The rendering engine can calculate its color based on the material of each triangle and the lighting angle in the scene.

   

In fact, it is three points to determine a plane. The calculation on a plane is the simplest, with the least factors taken into consideration. If three vertices in a 3D space are used as the basic rendering unit, rendering computation is quite complex if these vertices are not on the same plane.

The surface of a 3D object is called a grid (MeshA grid is defined by many 3D points. These points are called vertices (Vertices). These vertices are connected by winding pattern to form a triangle (Facet) (As shown in the arrow ).

<Viewport3D> Children... </Viewport3D>

  

This graphic system regards Viewport3D as a two-dimensional visualization element like many other elements in WPF. Viewport3D acts as a window (view area) in a 3D scenario ). More accurately, it is the surface projected by a 3D scene.

Camera

Developers who process 2D objects are used to placing drawing elements on 2D screens. When creating a 3D scenario, remember that you actually want to create a 2D representation of a 3D object. Because the appearance of a 3D scene varies with the observed position of the observer, you must specify the observed position. The observation position is specified by the Camera (Camera class) for three-dimensional scenes.

 

Another way to understand the description of a 3D scene on a two-dimensional graph is to project a 3D scene to a 2D plane surface. For example:

Place at least one light in the scenario to illuminate the model in our scenario.

Different types of light sources are supported in WPF, as follows:

  • AmbientLight (ambient light)The environment light provided by it illuminates all objects, regardless of the object's location or direction.
  • DirectionalLight (parallel light)Illuminating like a distant light source (such as sunlight ). Specify the Direction of light as Vector3D, but not the Direction of light.
  • PointLight)It is illuminated like a nearby light source. PointLight has a position from which the light is projected. Objects in a scenario are illuminated based on the position and distance of the object relative to the light source. PointLightBase exposes the Range attribute, which determines a distance. When the distance is exceeded, the model cannot be illuminated by the light source. PointLight also exposes multiple attenuation attributes that determine how the brightness of a light source decreases as the distance increases. You can specify a constant, linear, or quadratic interpolation algorithm for Attenuation of a light source.
  • SpotLight)Inherit from PointLight. Spotlight is similar to PointLight, but it has both location and direction. They place light in the conical area (in degrees) set by the InnerConeAngle and OuterConeAngle attributes.

Displays various light sources:

It currently does not support predefined 3D elements (such as sphere and cube ). First, you can create a MeshGeometry3D by specifying the triangle vertex list as its Positions attribute. Each vertex is specified as Point3D. (In eXtensible Application Markup Language (XAML), you can specify this attribute as a list of three numbers in one group, with three numbers in each group representing the coordinates of each vertex ). Based on the geometric shape of the mesh, the mesh may consist of multiple triangles, some of which share the same angle (vertex ). To draw a grid correctly, WPF needs information about which vertices are shared by which triangles. You can provide this information by specifying the Triangle Index list with the TriangleIndices attribute. This list specifies the order in which the triangle is determined by the point specified in the Positions list.

 

Material (Material)

We live in a colorful world and cannot make our 3D models so monotonous. At this time, we use materials.

<UserControl x: Class = "HostingWpfUserControlInWf. UserControl1" xmlns =" http://schemas.microsoft.com/winfx/2006/xaml /Presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "> <Grid> <! -- Place a Label control at the top of the view. --> <Label HorizontalAlignment = "Center" TextBlock. textAlignment = "Center" FontSize = "20" Foreground = "Red" Content = "Model: Cone"/> <! -- Viewport3D is the rendering surface. --> <Viewport3D Name = "myViewport"> <! -- Add a camera. --> <Viewport3D. camera> <PerspectiveCamera FarPlaneDistance = "20" LookDirection = ", 1" UpDirection = ", 0" NearPlaneDistance = "1" Position =, -3 "FieldOfView =" 45 "/> </Viewport3D. camera> <! -- Add models. --> <Viewport3D. Children> <ModelVisual3D> <ModelVisual3D. Content> <Model3DGroup> <Model3DGroup. Children> <! -- Lights, MeshGeometry3D and DiffuseMaterial objects are added to the ModelVisual3D. --> <DirectionalLight Color = "# FFFFFFFF" Direction = "3,-4, 5"/> <! -- Define a red cone. --> <GeometryModel3D> <GeometryModel3D. geometry> <MeshGeometry3D Positions = "0.293893-0.5 0.404509 0.475528-0.5 0.154509 0 0.5-0.475528 0.5 0.154509 0 0.5 0 0.5-0.475528 0.5 0.154509-0.475528-0.5 0 0.154509 0 0.475528-0.5-0.154509 0 0.5 0 0.5 0 0.475528-0.5-0.154509 0.293893-0.5-0.404509 0 0.5 0 0.293893-0.5-0.404509 0 0.5 0 0.5 0 0.293893-0.5-0.404509 0-0.5-0.5 0 0.5 0-0.5-0.5 0 0.5 0 0 0.5 0-0.5-0.5-0.293893-0.5-0.404509 0 0.5-0.293893-0.5-0.404509 0 0.5 0 0 0.5 0-0.293893-0.5-0.404509-0.475528-0.5-0.154509 0 0.5 0-0.475528-0.5-0.154509 0 0.5 0 0 0.5-0.475528-0.5-0.154509-0.475528 -0.5 0.154509 0 0.5 0-0.475528-0.5 0.154509 0 0.5 0 0 0.5-0.475528-0.5 0.154509-0.293892-0.5 0.404509 0 0.5 0-0.293892-0.5 0.404509 0 0.5 0 0 0.5 0-0.293892-0.5 0.404509 0-0.5 0.5 0 0.5 0-0.5 0.5 0 0.5 0 0 0 0.5 0-0.5 0.5 0.293893-0.5 0.404509 0.5 0 0.293893-0.5 0.404509 0.5 0 0 0 0 0 0.5 0 "Normals =" 0.7236065, 0.4472139, 0.5257313 0.2763934, 0.4472138, 0.8506507 0.5308242, 0.4294462, 0.7306172, 0.2763934, 0.4472138, 0.8506507, 0.4294458, 0.9030925, 0.5308242, 0.4294462, 0.7306172, 0.2763934, 0.4472138-0.8506507, 0.2763934, 0.4472138, 0.8506507 0, 0.4294458, 0.9030925-0.2763934, 0.4472138, 0.8506507-0.5308242, 0.4294462, 0.7306172, 0.4294458, 0.9030925-0.2763934, 0.4472138-0.8506507, 0.7236065-0.4472139, 0.5257313-0.5308242, 0.4294462, 0.7306172-0.7236065, 0.4472139, 0.5257313-0.858892, 0.429446-0.279071, 0.5308242, 0.4294462-0.7306172, 0.7236065-0.4472139, 0.5257313-0.8944269, 0.4472139-0.858892, 0.429446-0.279071, 0.8944269, 0.4472139, 0-0.858892, 0.429446,-0.279071-0.858892, 0.429446, 0.279071-0.8944269, 0.4472139, 0-0.7236065, 0.4472139,-0.5257313-0.858892, 0.429446,-0.279071-0.7236065, 0.4472139,-0.5257313-0.5308242, 0.4294462,-0.7306172-0.858892, 0.429446,-0.279071-0.7236065, 0.4472139,-0.5257313-0.2763934, 0.4472138,-0.8506507-0.5308242, 0.4294462, -0.7306172-0.2763934, 0.4472138,-0.8506507 0, 0.4294458,-0.9030925-0.5308242, 0.4294462,-0.7306172-0.2763934, 0.4472138,-0.8506507 0.2763934 0.4472138,-0.8506507 0, 0.4294458, -0.9030925 0.2763934, 0.4472138,-0.8506507 0.5308249, 0.4294459,-0.7306169 0, 0.4294458,-0.9030925 0.2763934, 0.4472138,-0.8506507 0.7236068 0.4472141,-0.5257306 0.5308249,-0.4294459 0.7306169, 0.4472141,-0.5257306 0.8588922, 0.4294461,-0.27907 0.5308249, 0.4294459,-0.7306169 0.7236068, 0.4472141,-0.5257306 0.8944269, 0.4472139, 0 0.8588922, 0.4294461,-0.27907 0.8944269, 0.4472139, 0 0.858892, 0.429446, 0.279071 0.8588922, 0.4294461,-0.27907 0.8944269, 0.4472139, 0 0.7236065, 0.4472139, 0.5257313 0.858892, 0.429446, 0.279071, 0.7236065, 0.4472139, 0.5257313, 0.5308242, 0.4294462, 0.7306172, 0.858892, 0.429446, 0.279071 "TriangleIndices =" 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 48 49 50 51 52 53 54 55 57 58 59 "/> </GeometryModel3D. geometry> <GeometryModel3D. material> <DiffuseMaterial. brush> <SolidColorBrush Color = "Red" Opacity = "1.0"/> </DiffuseMaterial. brush> </DiffuseMaterial> </GeometryModel3D. material> </GeometryModel3D> </Model3DGroup. children> </Model3DGroup> </ModelVisual3D. content> </ModelVisual3D> </Viewport3D. children> </Viewport3D> </Grid> </UserControl>

 

 

Make a 3D cube with pictures on its sides with XAML and C # source code

Summary

3D development must first clarify the 3D coordinate system to build the desired 3D Model, so that the light can be properly shining on the 3D Model (except ambient light) to produce different lighting effects, you can specify a proper Camera (Camera) position to see the 3D projection you want to see.

All the ry in 3D development is eventually composed of a series of triangles. Therefore, you must consider splitting your 3D model into a triangle on the premise that your 3D coordinate system is in high definition. It sounds complicated. Fortunately, there are some helper classes to help you deal with the decomposition of these triangles, and what you do is to provide the coordinate system of the key points.

 

Since WPF 3D is based on Direct 3D, it is directly rendered using the graphics card like WPF 2D, and panoramic anti-sawtooth is enabled by default (with one condition, your video card must be compatible with WDDM-Compliant ).

 

3D development and 2D development are much more complicated, and there are more things to consider. But for a more real and cool effect, it is worth learning.

 

Wish you a pleasant journey in 3D development!

Reference

WPF 3D Article, Tutorial with Chart Graphics C # Code

WPF-3D-Primer

Getting started with 3D in WPF

3D graphics Overview

Rendering Transparent 3D Surfaces in WPF with C #

Ambient, diffuse, emissive and specular colors: some examples

Related Article

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.