-
Notifications
You must be signed in to change notification settings - Fork 24
/
Surface.cs
97 lines (78 loc) · 2.72 KB
/
Surface.cs
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
using System;
using System.Windows;
using System.Windows.Media.Media3D;
namespace Surfaces
{
public abstract class Surface : ModelVisual3D
{
public Surface()
{
Content = _content;
_content.Geometry = CreateMesh();
}
public static PropertyHolder<Material, Surface> MaterialProperty =
new PropertyHolder<Material,Surface>("Material", null, OnMaterialChanged);
public static PropertyHolder<Material, Surface> BackMaterialProperty =
new PropertyHolder<Material, Surface>("BackMaterial", null, OnBackMaterialChanged);
public static PropertyHolder<bool, Surface> VisibleProperty =
new PropertyHolder<bool, Surface>("Visible", true, OnVisibleChanged);
public Material Material
{
get { return MaterialProperty.Get(this); }
set { MaterialProperty.Set(this, value); }
}
public Material BackMaterial
{
get { return BackMaterialProperty.Get(this); }
set { BackMaterialProperty.Set(this, value); }
}
public bool Visible
{
get { return VisibleProperty.Get(this); }
set { VisibleProperty.Set(this, value); }
}
private static void OnMaterialChanged(Object sender, DependencyPropertyChangedEventArgs e)
{
((Surface)sender).OnMaterialChanged();
}
private static void OnBackMaterialChanged(Object sender, DependencyPropertyChangedEventArgs e)
{
((Surface)sender).OnBackMaterialChanged();
}
private static void OnVisibleChanged(Object sender, DependencyPropertyChangedEventArgs e)
{
((Surface)sender).OnVisibleChanged();
}
protected static void OnGeometryChanged(Object sender, DependencyPropertyChangedEventArgs e)
{
((Surface)sender).OnGeometryChanged();
}
private void OnMaterialChanged()
{
SetContentMaterial();
}
private void OnBackMaterialChanged()
{
SetContentBackMaterial();
}
private void OnVisibleChanged()
{
SetContentMaterial();
SetContentBackMaterial();
}
private void SetContentMaterial()
{
_content.Material = Visible ? Material : null;
}
private void SetContentBackMaterial()
{
_content.BackMaterial = Visible ? BackMaterial : null;
}
private void OnGeometryChanged()
{
_content.Geometry = CreateMesh();
}
protected abstract Geometry3D CreateMesh();
private readonly GeometryModel3D _content = new GeometryModel3D();
}
}