WPF itself does not support direct 3D drawing, but it provides some advanced techniques for achieving 3D effects.
If you want to do 3D drawing in WPF, you can use two main methods:
-
WPF 3D: This is a way to create 3D graphics in WPF applications. WPF 3D provides some basic 3D shapes (such as cubes, spheres, and cones) as well as some tools for controlling 3D scenes and objects (such as cameras, lights, and materials).
In WPF, the following three materials can be used for 3D object models:
-
DiffuseMaterial: diffuse reflection, reflection scene light effect
-
EmissiveMaterial: self-illuminating, similar to an electric light
-
SpecularMaterial: total reflection, can map scene maps
In WPF, the material of a 3D model is a very important element that determines what the model looks like, such as roughness, color, luminosity, etc.
The WPF 3D object model light source is as follows
AmbientLight: Ambient Light - Provides ambient light that illuminates all objects regardless of their position or orientation.
DirectionalLight: directional light - it illuminates like a distant light source (such as sunlight), has only a Direction property and no position information, so it does not cast directly on any specific object, but illuminates all objects in the scene .
PointLight: Point light - Illuminates like a nearby light source, has a position and casts light from that position, objects in the scene are illuminated based on the object's position and distance relative to the light source.
SpotLight: Spotlight - Inherited from PointLight, it lights similarly to PointLight, but it has both position and direction.
Related properties
Color: light color
Direction: light direction (parallel light, spotlight)
Position: light source coordinates (point light source, spotlight)
Range: light range (point light source)
InnerConeAngle: inner light beam illumination angle (spotlight)
OuterConeAngle: External light beam illumination angle (spotlight)
Attributes |
illustrate |
Remark |
MeshGemetry3D |
grid label |
|
Positions |
point |
Labels that present 3D graphics Positions="0,0,0 (x,y,z) 3,0,0 3,2,0 0,2,0" 4 points of a surface |
TraiangleIndices |
3 Angular creation |
TriangleIndices="0,3,2 (first group) 0,1,2 (second group)" Set the 3 points of Positions to form a triangle row |
OrthographicCamera |
Orthographic camera (near and far ratios are the same - rarely used) |
|
PerspectiveCamera |
Perspective camera (the near ratio is small and the long distance ratio is small, in line with our normal vision of observing things - commonly used) |
|
TextureCoordinates |
Set the mapping relationship between plane objects and 3D objects - used to solve the problem of displaying the background image of plane settings - if this property is not set, the background image of plane settings will not be displayed. |
TextureCoordinates="1,1 1,0 0,0 0,1" |
Camera tag object properties
Attributes | illustrate | Remark |
Position | Camera spatial coordinates (X, Y, Z) | Position="100,100,100" Set the viewing angle x,y,z |
LookDirection | Observation direction, vector, camera observation port orientation | LookDirection="-2,-2,-2" sets the camera's viewing angle - the direction of the camera's observation |
FieldOfView | (perspective camera property) / field of view, one value | FieldOfView="90" sets the distance between the camera and the viewing object. The farther away the viewing object area is, the larger the viewing area is, and the closer the viewing object area is smaller. |
Width | (orthographic camera properties) (focal length), field of view | Width="50" |
UpDirection | The direction above the camera, controls the rotation of the camera observation port | UpDirection="0,1,0" (x, y, z) sets the rotation angle of the camera viewport, whether to shoot at an angle or straight up. |
FarPlaneDistance | Distant distance. Scenes larger than this distance will not be rendered. | FarPlaneDistance="1000" 设置相机远处景色的渲染范围,如果值设置的比较小,远处景色是模糊的 |
NearPlaneDistance | 近景距离,小于这个距离的场景不渲染 | NearPlaneDistance="1" 设置相机近处的晶圆渲染范围,如果值越大,近处景色是模糊的 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
后台关于3D地球的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
代码实例效果图:
这个3D动画地球是可以旋转的
3D图片用于辅助寻找3d坐标点顺序
3D面设置背景图显示方向
通过TextureCoordinates属性设置箭头的显示方向
TextureCoordinates="1,1 1,0 0,0 0,1"/> <!--箭头向下-->
<!--TextureCoordinates="1,1 0,1 0,0 1,0"/> 箭头向左-->
<!--TextureCoordinates="0,1 1,1 1,0 0,0"/> 箭头向右-->
<!--TextureCoordinates="0,1 0,0 1,0 1,1"/>--><!-- 箭头向上-->
本文章大半部分素材来自于朝夕教育,技术整理的不好。。。