|
3 | 3 | import math.Mathf; |
4 | 4 | import mesh.Mesh3D; |
5 | 5 | import mesh.modifier.SolidifyModifier; |
| 6 | +import mesh.modifier.TranslateModifier; |
6 | 7 |
|
7 | 8 | public class BeamCProfileCreator implements IBeamCreator { |
8 | 9 |
|
9 | | - private float width; |
| 10 | + private float width; |
10 | 11 |
|
11 | | - private float height; |
12 | | - |
13 | | - private float depth; |
| 12 | + private float height; |
| 13 | + |
| 14 | + private float depth; |
14 | 15 |
|
15 | | - private float thickness; |
16 | | - |
17 | | - private float taper; |
| 16 | + private float thickness; |
| 17 | + |
| 18 | + private float taper; |
18 | 19 |
|
19 | | - private Mesh3D mesh; |
20 | | - |
21 | | - public BeamCProfileCreator() { |
22 | | - height = 0.85f; |
23 | | - width = 0.5f; |
24 | | - depth = 2.0f; |
25 | | - thickness = 0.1f; |
26 | | - taper = 0.0f; |
27 | | - } |
28 | | - |
29 | | - @Override |
30 | | - public Mesh3D create() { |
31 | | - initializeMesh(); |
32 | | - createVertices(); |
33 | | - createFaces(); |
34 | | - rotate(); |
35 | | - solidify(); |
36 | | - center(); |
37 | | - return mesh; |
38 | | - } |
39 | | - |
40 | | - private void initializeMesh() { |
41 | | - mesh = new Mesh3D(); |
42 | | - } |
43 | | - |
44 | | - private void createVertices() { |
45 | | - float halfHeight = height / 2f; |
46 | | - |
47 | | - addVertex(-halfHeight, 0, 0); |
48 | | - addVertex(+halfHeight, 0, 0); |
49 | | - addVertex(-halfHeight, -width, 0); |
50 | | - addVertex(+halfHeight, -width, 0); |
51 | | - addVertex(-halfHeight + thickness, -thickness, 0); |
52 | | - addVertex(+halfHeight - thickness, -thickness, 0); |
53 | | - addVertex(-halfHeight + (thickness * (1f - taper)), -width, 0); |
54 | | - addVertex(+halfHeight - (thickness * (1f - taper)), -width, 0); |
55 | | - } |
56 | | - |
57 | | - private void createFaces() { |
58 | | - addFace(0, 4, 5, 1); |
59 | | - addFace(0, 2, 6, 4); |
60 | | - addFace(5, 7, 3, 1); |
61 | | - } |
62 | | - |
63 | | - private void addVertex(float x, float y, float z) { |
64 | | - mesh.addVertex(x, y, z); |
65 | | - } |
66 | | - |
67 | | - private void addFace(int... indices) { |
68 | | - mesh.addFace(indices); |
69 | | - } |
70 | | - |
71 | | - private void rotate() { |
72 | | - mesh.rotateZ(Mathf.HALF_PI); |
73 | | - } |
74 | | - |
75 | | - private void solidify() { |
76 | | - new SolidifyModifier(depth).modify(mesh); |
77 | | - } |
78 | | - |
79 | | - private void center() { |
80 | | - mesh.translate(-width / 2f, 0, depth / 2f); |
81 | | - } |
82 | | - |
83 | | - public float getWidth() { |
84 | | - return width; |
85 | | - } |
86 | | - |
87 | | - public void setWidth(float width) { |
88 | | - this.width = width; |
89 | | - } |
90 | | - |
91 | | - public float getHeight() { |
92 | | - return height; |
93 | | - } |
94 | | - |
95 | | - public void setHeight(float height) { |
96 | | - this.height = height; |
97 | | - } |
98 | | - |
99 | | - public float getDepth() { |
100 | | - return depth; |
101 | | - } |
102 | | - |
103 | | - public void setDepth(float depth) { |
104 | | - this.depth = depth; |
105 | | - } |
106 | | - |
107 | | - public float getThickness() { |
108 | | - return thickness; |
109 | | - } |
110 | | - |
111 | | - public void setThickness(float thickness) { |
112 | | - this.thickness = thickness; |
113 | | - } |
114 | | - |
115 | | - public float getTaper() { |
116 | | - return taper; |
117 | | - } |
118 | | - |
119 | | - public void setTaper(float taper) { |
120 | | - this.taper = Mathf.clamp(taper, 0.0f, 1.0f); |
121 | | - } |
| 20 | + private Mesh3D mesh; |
| 21 | + |
| 22 | + public BeamCProfileCreator() { |
| 23 | + height = 0.85f; |
| 24 | + width = 0.5f; |
| 25 | + depth = 2.0f; |
| 26 | + thickness = 0.1f; |
| 27 | + taper = 0.0f; |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public Mesh3D create() { |
| 32 | + initializeMesh(); |
| 33 | + createVertices(); |
| 34 | + createFaces(); |
| 35 | + rotate(); |
| 36 | + solidify(); |
| 37 | + center(); |
| 38 | + return mesh; |
| 39 | + } |
| 40 | + |
| 41 | + private void initializeMesh() { |
| 42 | + mesh = new Mesh3D(); |
| 43 | + } |
| 44 | + |
| 45 | + private void createVertices() { |
| 46 | + float halfHeight = height / 2f; |
| 47 | + |
| 48 | + addVertex(-halfHeight, 0, 0); |
| 49 | + addVertex(+halfHeight, 0, 0); |
| 50 | + addVertex(-halfHeight, -width, 0); |
| 51 | + addVertex(+halfHeight, -width, 0); |
| 52 | + addVertex(-halfHeight + thickness, -thickness, 0); |
| 53 | + addVertex(+halfHeight - thickness, -thickness, 0); |
| 54 | + addVertex(-halfHeight + (thickness * (1f - taper)), -width, 0); |
| 55 | + addVertex(+halfHeight - (thickness * (1f - taper)), -width, 0); |
| 56 | + } |
| 57 | + |
| 58 | + private void createFaces() { |
| 59 | + addFace(0, 4, 5, 1); |
| 60 | + addFace(0, 2, 6, 4); |
| 61 | + addFace(5, 7, 3, 1); |
| 62 | + } |
| 63 | + |
| 64 | + private void addVertex(float x, float y, float z) { |
| 65 | + mesh.addVertex(x, y, z); |
| 66 | + } |
| 67 | + |
| 68 | + private void addFace(int... indices) { |
| 69 | + mesh.addFace(indices); |
| 70 | + } |
| 71 | + |
| 72 | + private void rotate() { |
| 73 | + mesh.rotateZ(Mathf.HALF_PI); |
| 74 | + } |
| 75 | + |
| 76 | + private void solidify() { |
| 77 | + new SolidifyModifier(depth).modify(mesh); |
| 78 | + } |
| 79 | + |
| 80 | + private void center() { |
| 81 | + mesh.apply(new TranslateModifier(-width / 2f, 0, depth / 2f)); |
| 82 | + } |
| 83 | + |
| 84 | + public float getWidth() { |
| 85 | + return width; |
| 86 | + } |
| 87 | + |
| 88 | + public void setWidth(float width) { |
| 89 | + this.width = width; |
| 90 | + } |
| 91 | + |
| 92 | + public float getHeight() { |
| 93 | + return height; |
| 94 | + } |
| 95 | + |
| 96 | + public void setHeight(float height) { |
| 97 | + this.height = height; |
| 98 | + } |
| 99 | + |
| 100 | + public float getDepth() { |
| 101 | + return depth; |
| 102 | + } |
| 103 | + |
| 104 | + public void setDepth(float depth) { |
| 105 | + this.depth = depth; |
| 106 | + } |
| 107 | + |
| 108 | + public float getThickness() { |
| 109 | + return thickness; |
| 110 | + } |
| 111 | + |
| 112 | + public void setThickness(float thickness) { |
| 113 | + this.thickness = thickness; |
| 114 | + } |
| 115 | + |
| 116 | + public float getTaper() { |
| 117 | + return taper; |
| 118 | + } |
| 119 | + |
| 120 | + public void setTaper(float taper) { |
| 121 | + this.taper = Mathf.clamp(taper, 0.0f, 1.0f); |
| 122 | + } |
122 | 123 |
|
123 | 124 | } |
0 commit comments