Skip to content

Commit 089f7f4

Browse files
committed
Format changes.
1 parent 7e0d068 commit 089f7f4

31 files changed

+4176
-4462
lines changed

src/main/java/mesh/modifier/BendModifier.java

Lines changed: 99 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -6,131 +6,117 @@
66

77
/**
88
* A modifier that bends a 3D mesh along the X-axis.
9-
*
10-
* This modifier applies a simple bending deformation to each vertex of the
11-
* given 3D mesh. The degree of bending is controlled by the {@code factor}
12-
* parameter. A higher factor results in a more pronounced bend. Extreme bending
13-
* may distort or cause self-intersection depending on the value of the factor.
9+
*
10+
* <p>This modifier applies a simple bending deformation to each vertex of the given 3D mesh. The
11+
* degree of bending is controlled by the {@code factor} parameter. A higher factor results in a
12+
* more pronounced bend. Extreme bending may distort or cause self-intersection depending on the
13+
* value of the factor.
1414
*/
1515
public class BendModifier implements IMeshModifier {
1616

17-
/**
18-
* A very small value used to determine if the bending factor is effectively
19-
* zero.
20-
*/
21-
private static final float EPSILON = 1e-7f;
17+
/** A very small value used to determine if the bending factor is effectively zero. */
18+
private static final float EPSILON = 1e-7f;
2219

23-
/**
24-
* The bending factor determining the degree of bending along the X-axis.
25-
* Default value is 0.5.
26-
*/
27-
private float factor;
20+
/**
21+
* The bending factor determining the degree of bending along the X-axis. Default value is 0.5.
22+
*/
23+
private float factor;
2824

29-
/**
30-
* A modifier that bends a mesh along the X-axis.
31-
*
32-
* The bending is controlled by the `factor` parameter. Default is 0.5f,
33-
* introducing a subtle bend.
34-
*/
35-
public BendModifier() {
36-
this(0.5f);
37-
}
25+
/**
26+
* A modifier that bends a mesh along the X-axis.
27+
*
28+
* <p>The bending is controlled by the `factor` parameter. Default is 0.5f, introducing a subtle
29+
* bend.
30+
*/
31+
public BendModifier() {
32+
this(0.5f);
33+
}
3834

39-
/**
40-
* Constructor to specify a custom bending factor.
41-
*
42-
* @param factor the bending factor controlling the degree of bending. Higher
43-
* values cause more bending, but extreme values can distort the
44-
* mesh.
45-
*/
46-
public BendModifier(float factor) {
47-
this.factor = factor;
48-
}
35+
/**
36+
* Constructor to specify a custom bending factor.
37+
*
38+
* @param factor the bending factor controlling the degree of bending. Higher values cause more
39+
* bending, but extreme values can distort the mesh.
40+
*/
41+
public BendModifier(float factor) {
42+
this.factor = factor;
43+
}
4944

50-
/**
51-
* Modifies the provided mesh by applying bending to its vertices along the
52-
* X-axis. If the provided mesh contains no vertices, the method safely
53-
* returns the mesh without changes.
54-
* <p>
55-
* The bending is only applied if the {@link #factor} value is valid (greater
56-
* than a small threshold, defined by {@link #EPSILON}). This prevents the
57-
* mesh from being unnecessarily modified when the bending factor is
58-
* negligible and would result in division by zero issues.
59-
* </p>
60-
*
61-
* @param mesh the 3D mesh to bend. Cannot be {@code null}.
62-
* @return the modified mesh after applying bending, or the original mesh if
63-
* no changes are applied.
64-
* @throws IllegalArgumentException if {@code mesh} is null.
65-
*/
66-
@Override
67-
public Mesh3D modify(Mesh3D mesh) {
68-
if (mesh == null) {
69-
throw new IllegalArgumentException("Mesh cannot be null.");
70-
}
71-
if (mesh.vertices.isEmpty()) {
72-
return mesh;
73-
}
74-
if (isFactorValid())
75-
bend(mesh);
76-
return mesh;
77-
}
45+
/**
46+
* Modifies the provided mesh by applying bending to its vertices along the X-axis. If the
47+
* provided mesh contains no vertices, the method safely returns the mesh without changes.
48+
*
49+
* <p>The bending is only applied if the {@link #factor} value is valid (greater than a small
50+
* threshold, defined by {@link #EPSILON}). This prevents the mesh from being unnecessarily
51+
* modified when the bending factor is negligible and would result in division by zero issues.
52+
*
53+
* @param mesh the 3D mesh to bend. Cannot be {@code null}.
54+
* @return the modified mesh after applying bending, or the original mesh if no changes are
55+
* applied.
56+
* @throws IllegalArgumentException if {@code mesh} is null.
57+
*/
58+
@Override
59+
public Mesh3D modify(Mesh3D mesh) {
60+
if (mesh == null) {
61+
throw new IllegalArgumentException("Mesh cannot be null.");
62+
}
63+
if (mesh.vertices.isEmpty()) {
64+
return mesh;
65+
}
66+
if (isFactorValid()) bend(mesh);
67+
return mesh;
68+
}
7869

79-
/**
80-
* Performs the bending operation on all vertices of the provided mesh using
81-
* parallel processing.
82-
*
83-
* @param mesh the 3D mesh whose vertices are to be deformed.
84-
*/
85-
private void bend(Mesh3D mesh) {
86-
mesh.vertices.parallelStream().forEach(this::simpleDeformBend);
87-
}
70+
/**
71+
* Performs the bending operation on all vertices of the provided mesh using parallel processing.
72+
*
73+
* @param mesh the 3D mesh whose vertices are to be deformed.
74+
*/
75+
private void bend(Mesh3D mesh) {
76+
mesh.vertices.parallelStream().forEach(this::simpleDeformBend);
77+
}
8878

89-
/**
90-
* Applies the bending transformation to a single vertex based on the bending
91-
* equation.
92-
*
93-
* @param v the vertex to deform.
94-
*/
95-
private void simpleDeformBend(Vector3f v) {
96-
float theta = v.x * factor;
97-
float sinTheta = Mathf.sin(theta);
98-
float cosTheta = Mathf.cos(theta);
79+
/**
80+
* Applies the bending transformation to a single vertex based on the bending equation.
81+
*
82+
* @param v the vertex to deform.
83+
*/
84+
private void simpleDeformBend(Vector3f v) {
85+
float theta = v.x * factor;
86+
float sinTheta = Mathf.sin(theta);
87+
float cosTheta = Mathf.cos(theta);
9988

100-
float bx = -(v.y - 1.0f / factor) * sinTheta;
101-
float by = (v.y - 1.0f / factor) * cosTheta + 1.0f / factor;
102-
float bz = v.z;
89+
float bx = -(v.y - 1.0f / factor) * sinTheta;
90+
float by = (v.y - 1.0f / factor) * cosTheta + 1.0f / factor;
91+
float bz = v.z;
10392

104-
v.set(bx, by, bz);
105-
}
93+
v.set(bx, by, bz);
94+
}
10695

107-
/**
108-
* Checks if the bending factor is valid (i.e., not effectively zero).
109-
*
110-
* @return {@code true} if the factor is a valid number for bending,
111-
* {@code false} otherwise.
112-
*/
113-
private boolean isFactorValid() {
114-
return Mathf.abs(factor) > EPSILON;
115-
}
96+
/**
97+
* Checks if the bending factor is valid (i.e., not effectively zero).
98+
*
99+
* @return {@code true} if the factor is a valid number for bending, {@code false} otherwise.
100+
*/
101+
private boolean isFactorValid() {
102+
return Mathf.abs(factor) > EPSILON;
103+
}
116104

117-
/**
118-
* Gets the current bending factor value.
119-
*
120-
* @return the bending factor value.
121-
*/
122-
public float getFactor() {
123-
return factor;
124-
}
125-
126-
/**
127-
* Sets the bending factor to a new value.
128-
*
129-
* @param factor the new bending factor value. Higher values result in more
130-
* bending.
131-
*/
132-
public void setFactor(float factor) {
133-
this.factor = factor;
134-
}
105+
/**
106+
* Gets the current bending factor value.
107+
*
108+
* @return the bending factor value.
109+
*/
110+
public float getFactor() {
111+
return factor;
112+
}
135113

114+
/**
115+
* Sets the bending factor to a new value.
116+
*
117+
* @param factor the new bending factor value. Higher values result in more bending.
118+
*/
119+
public void setFactor(float factor) {
120+
this.factor = factor;
121+
}
136122
}

src/main/java/mesh/modifier/BevelEdgesModifier.java

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,18 @@ public Mesh3D modify(Mesh3D mesh) {
5656
setMesh(mesh);
5757
clearAll();
5858

59-
createInsetFaces();
59+
insetFaces();
6060

6161
createFacesForOldEdges();
62-
createFacesVertex();
62+
createFacesAroundVertices();
6363

64-
clearOriginalFaces();
65-
clearOriginalVertices();
66-
67-
addNewVertices();
68-
addNewFaces();
64+
clearOriginalGeometry();
65+
addNewGeometry();
6966

7067
return mesh;
7168
}
7269

73-
private void createFacesVertex() {
70+
private void createFacesAroundVertices() {
7471
TraverseHelper helper = new TraverseHelper(mesh);
7572
for (int i = 0; i < mesh.getVertexCount(); i++) {
7673
Edge3D outgoingEdge = helper.getOutgoing(i);
@@ -93,18 +90,17 @@ private void createFacesForOldEdges() {
9390
}
9491

9592
private void createFaceForOldEdgeAt(Face3D face, int i) {
96-
Edge3D edge = edgeProcessor
97-
.getMappedEdge(edgeProcessor.createEdge(face.indices, i));
98-
Edge3D pair = edgeProcessor
99-
.getMappedEdge(edgeProcessor.createEdge(face.indices, i).createPair());
93+
EdgeProcessor p = edgeProcessor;
94+
Edge3D edge = p.getMappedEdge(p.createEdge(face.indices, i));
95+
Edge3D pair = p.getMappedEdge(p.createEdge(face.indices, i).createPair());
10096

101-
if (edgeProcessor.isProcessed(edge) || edgeProcessor.isProcessed(pair))
97+
if (p.isProcessed(edge) || p.isProcessed(pair))
10298
return;
10399

104100
createFaceForEdge(edge, pair);
105101

106-
edgeProcessor.markProcessed(edge);
107-
edgeProcessor.markProcessed(pair);
102+
p.markProcessed(edge);
103+
p.markProcessed(pair);
108104
}
109105

110106
private void createFaceForEdge(Edge3D edge, Edge3D pair) {
@@ -116,13 +112,7 @@ private int[] toReverseArray(List<Integer> values) {
116112
return values.stream().mapToInt(x -> x).toArray();
117113
}
118114

119-
private void clearAll() {
120-
edgeProcessor.clearAll();
121-
verticesToAdd.clear();
122-
facesToAdd.clear();
123-
}
124-
125-
private void createInsetFaces() {
115+
private void insetFaces() {
126116
for (Face3D face : mesh.faces)
127117
insetFace(mesh, face);
128118
}
@@ -193,14 +183,12 @@ private float calculateInsetFactor(float edgeLength) {
193183
}
194184

195185
private float getAmountByWidthType() {
196-
float amount;
197-
switch (widthType) {
198-
case OFFSET -> amount = this.amount * 2;
199-
case WIDTH -> amount = inset;
200-
case DEPTH -> amount = inset * 2;
201-
default -> amount = this.amount * 2;
202-
}
203-
return amount;
186+
return switch (widthType) {
187+
case OFFSET -> amount * 2;
188+
case WIDTH -> inset;
189+
case DEPTH -> inset * 2;
190+
default -> amount * 2;
191+
};
204192
}
205193

206194
private boolean canExitEarly(Mesh3D mesh) {
@@ -217,6 +205,22 @@ private Vector3f getVertexAt(Face3D face, int index) {
217205
return mesh.getVertexAt(face.indices[index % face.indices.length]);
218206
}
219207

208+
private void clearAll() {
209+
edgeProcessor.clearAll();
210+
verticesToAdd.clear();
211+
facesToAdd.clear();
212+
}
213+
214+
private void clearOriginalGeometry() {
215+
clearOriginalFaces();
216+
clearOriginalVertices();
217+
}
218+
219+
private void addNewGeometry() {
220+
addNewVertices();
221+
addNewFaces();
222+
}
223+
220224
private void addNewVertices() {
221225
mesh.vertices.addAll(verticesToAdd);
222226
}

src/main/java/mesh/modifier/BevelFacesModifier.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,29 @@
55

66
public class BevelFacesModifier implements IMeshModifier {
77

8-
private float size;
9-
10-
public BevelFacesModifier() {
11-
setSize(0.1f);
12-
}
13-
14-
public BevelFacesModifier(float size) {
15-
this.size = Mathf.clamp(size, 0f, 1f);
16-
}
17-
18-
@Override
19-
public Mesh3D modify(Mesh3D mesh) {
20-
float scale = 1f - size;
21-
float amount = size;
22-
mesh.apply(new ExtrudeModifier(scale, amount));
23-
return mesh;
24-
}
25-
26-
public float getSize() {
27-
return size;
28-
}
29-
30-
public void setSize(float size) {
31-
this.size = Mathf.clamp(size, 0f, 1f);
32-
}
33-
8+
private float size;
9+
10+
public BevelFacesModifier() {
11+
setSize(0.1f);
12+
}
13+
14+
public BevelFacesModifier(float size) {
15+
this.size = Mathf.clamp(size, 0f, 1f);
16+
}
17+
18+
@Override
19+
public Mesh3D modify(Mesh3D mesh) {
20+
float scale = 1f - size;
21+
float amount = size;
22+
mesh.apply(new ExtrudeModifier(scale, amount));
23+
return mesh;
24+
}
25+
26+
public float getSize() {
27+
return size;
28+
}
29+
30+
public void setSize(float size) {
31+
this.size = Mathf.clamp(size, 0f, 1f);
32+
}
3433
}

0 commit comments

Comments
 (0)