Skip to content

Commit 1327f1e

Browse files
authored
Merge pull request #2420 from capdevon/capdevon-emitter-shape
EmitterShape: javadoc improvements
2 parents a905e41 + 52bdb34 commit 1327f1e

File tree

4 files changed

+153
-19
lines changed

4 files changed

+153
-19
lines changed

jme3-core/src/main/java/com/jme3/effect/shapes/EmitterBoxShape.java

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -40,13 +40,35 @@
4040
import com.jme3.util.clone.Cloner;
4141
import java.io.IOException;
4242

43+
/**
44+
* An {@link EmitterShape} that emits particles randomly within the bounds of an axis-aligned box.
45+
* The box is defined by a minimum corner and a length vector.
46+
*/
4347
public class EmitterBoxShape implements EmitterShape {
4448

45-
private Vector3f min, len;
49+
/**
50+
* The minimum corner of the box.
51+
*/
52+
private Vector3f min;
53+
/**
54+
* The length of the box along each axis. The x, y, and z components of this
55+
* vector represent the width, height, and depth of the box, respectively.
56+
*/
57+
private Vector3f len;
4658

59+
/**
60+
* For serialization only. Do not use.
61+
*/
4762
public EmitterBoxShape() {
4863
}
4964

65+
/**
66+
* Constructs an {@code EmitterBoxShape} defined by a minimum and maximum corner.
67+
*
68+
* @param min The minimum corner of the box.
69+
* @param max The maximum corner of the box.
70+
* @throws IllegalArgumentException If either {@code min} or {@code max} is null.
71+
*/
5072
public EmitterBoxShape(Vector3f min, Vector3f max) {
5173
if (min == null || max == null) {
5274
throw new IllegalArgumentException("min or max cannot be null");
@@ -57,6 +79,11 @@ public EmitterBoxShape(Vector3f min, Vector3f max) {
5779
this.len.set(max).subtractLocal(min);
5880
}
5981

82+
/**
83+
* Generates a random point within the bounds of the box.
84+
*
85+
* @param store The {@link Vector3f} to store the generated point in.
86+
*/
6087
@Override
6188
public void getRandomPoint(Vector3f store) {
6289
store.x = min.x + len.x * FastMath.nextRandomFloat();
@@ -65,10 +92,11 @@ public void getRandomPoint(Vector3f store) {
6592
}
6693

6794
/**
68-
* This method fills the point with data.
69-
* It does not fill the normal.
70-
* @param store the variable to store the point data
71-
* @param normal not used in this class
95+
* For a box shape, the normal is not well-defined for points within the volume.
96+
* This implementation simply calls {@link #getRandomPoint(Vector3f)} and does not modify the provided normal.
97+
*
98+
* @param store The {@link Vector3f} to store the generated point in.
99+
* @param normal The {@link Vector3f} to store the generated normal in (unused).
72100
*/
73101
@Override
74102
public void getRandomPointAndNormal(Vector3f store, Vector3f normal) {
@@ -108,18 +136,40 @@ public void cloneFields(Cloner cloner, Object original) {
108136
this.len = cloner.clone(len);
109137
}
110138

139+
/**
140+
* Returns the minimum corner of the emitting box.
141+
*
142+
* @return The minimum corner.
143+
*/
111144
public Vector3f getMin() {
112145
return min;
113146
}
114147

148+
/**
149+
* Sets the minimum corner of the emitting box.
150+
*
151+
* @param min The new minimum corner.
152+
*/
115153
public void setMin(Vector3f min) {
116154
this.min = min;
117155
}
118156

157+
/**
158+
* Returns the length vector of the emitting box. This vector represents the
159+
* extent of the box along each axis (length = max - min).
160+
*
161+
* @return The length vector.
162+
*/
119163
public Vector3f getLen() {
120164
return len;
121165
}
122166

167+
/**
168+
* Sets the length vector of the emitting box. This vector should represent
169+
* the extent of the box along each axis (length = max - min).
170+
*
171+
* @param len The new length vector.
172+
*/
123173
public void setLen(Vector3f len) {
124174
this.len = len;
125175
}

jme3-core/src/main/java/com/jme3/effect/shapes/EmitterPointShape.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -31,20 +31,35 @@
3131
*/
3232
package com.jme3.effect.shapes;
3333

34+
import com.jme3.export.InputCapsule;
3435
import com.jme3.export.JmeExporter;
3536
import com.jme3.export.JmeImporter;
3637
import com.jme3.export.OutputCapsule;
3738
import com.jme3.math.Vector3f;
3839
import com.jme3.util.clone.Cloner;
3940
import java.io.IOException;
4041

42+
/**
43+
* An {@link EmitterShape} that emits particles from a single point in space.
44+
*/
4145
public class EmitterPointShape implements EmitterShape {
4246

47+
/**
48+
* The point in space from which particles are emitted.
49+
*/
4350
private Vector3f point;
4451

52+
/**
53+
* For serialization only. Do not use.
54+
*/
4555
public EmitterPointShape() {
4656
}
4757

58+
/**
59+
* Constructs an {@code EmitterPointShape} with the given point.
60+
*
61+
* @param point The point from which particles are emitted.
62+
*/
4863
public EmitterPointShape(Vector3f point) {
4964
this.point = point;
5065
}
@@ -80,26 +95,43 @@ public void cloneFields(Cloner cloner, Object original) {
8095
this.point = cloner.clone(point);
8196
}
8297

98+
/**
99+
* For a point shape, the generated point is
100+
* always the shape's defined point.
101+
*
102+
* @param store The {@link Vector3f} to store the generated point in.
103+
*/
83104
@Override
84105
public void getRandomPoint(Vector3f store) {
85106
store.set(point);
86107
}
87108

88109
/**
89-
* This method fills the point with data.
90-
* It does not fill the normal.
91-
* @param store the variable to store the point data
92-
* @param normal not used in this class
110+
* For a point shape, the generated point is always the shape's defined point.
111+
* The normal is not defined for a point shape, so this method does not modify the normal parameter.
112+
*
113+
* @param store The {@link Vector3f} to store the generated point in.
114+
* @param normal The {@link Vector3f} to store the generated normal in (unused).
93115
*/
94116
@Override
95117
public void getRandomPointAndNormal(Vector3f store, Vector3f normal) {
96118
store.set(point);
97119
}
98120

121+
/**
122+
* Returns the point from which particles are emitted.
123+
*
124+
* @return The point.
125+
*/
99126
public Vector3f getPoint() {
100127
return point;
101128
}
102129

130+
/**
131+
* Sets the point from which particles are emitted.
132+
*
133+
* @param point The new point.
134+
*/
103135
public void setPoint(Vector3f point) {
104136
this.point = point;
105137
}
@@ -112,6 +144,7 @@ public void write(JmeExporter ex) throws IOException {
112144

113145
@Override
114146
public void read(JmeImporter im) throws IOException {
115-
this.point = (Vector3f) im.getCapsule(this).readSavable("point", null);
147+
InputCapsule ic = im.getCapsule(this);
148+
this.point = (Vector3f) ic.readSavable("point", null);
116149
}
117150
}

jme3-core/src/main/java/com/jme3/effect/shapes/EmitterShape.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -39,14 +39,14 @@
3939
* This interface declares methods used by all shapes that represent particle emitters.
4040
* @author Kirill
4141
*/
42-
public interface EmitterShape extends Savable, Cloneable, JmeCloneable {
42+
public interface EmitterShape extends Savable, JmeCloneable {
4343

4444
/**
4545
* This method fills in the initial position of the particle.
4646
* @param store
4747
* store variable for initial position
4848
*/
49-
public void getRandomPoint(Vector3f store);
49+
void getRandomPoint(Vector3f store);
5050

5151
/**
5252
* This method fills in the initial position of the particle and its normal vector.
@@ -55,11 +55,11 @@ public interface EmitterShape extends Savable, Cloneable, JmeCloneable {
5555
* @param normal
5656
* store variable for initial normal
5757
*/
58-
public void getRandomPointAndNormal(Vector3f store, Vector3f normal);
58+
void getRandomPointAndNormal(Vector3f store, Vector3f normal);
5959

6060
/**
6161
* This method creates a deep clone of the current instance of the emitter shape.
6262
* @return deep clone of the current instance of the emitter shape
6363
*/
64-
public EmitterShape deepClone();
64+
EmitterShape deepClone();
6565
}

jme3-core/src/main/java/com/jme3/effect/shapes/EmitterSphereShape.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2012 jMonkeyEngine
2+
* Copyright (c) 2009-2025 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -40,19 +40,38 @@
4040
import com.jme3.util.clone.Cloner;
4141
import java.io.IOException;
4242

43+
/**
44+
* An {@link EmitterShape} that emits particles randomly from within the volume of a sphere.
45+
* The sphere is defined by a center point and a radius.
46+
*/
4347
public class EmitterSphereShape implements EmitterShape {
4448

49+
/**
50+
* The center point of the sphere.
51+
*/
4552
private Vector3f center;
53+
/**
54+
* The radius of the sphere.
55+
*/
4656
private float radius;
4757

58+
/**
59+
* For serialization only. Do not use.
60+
*/
4861
public EmitterSphereShape() {
4962
}
5063

64+
/**
65+
* Constructs an {@code EmitterSphereShape} with the given center and radius.
66+
*
67+
* @param center The center point of the sphere.
68+
* @param radius The radius of the sphere.
69+
* @throws IllegalArgumentException If {@code center} is null, or if {@code radius} is not greater than 0.
70+
*/
5171
public EmitterSphereShape(Vector3f center, float radius) {
5272
if (center == null) {
5373
throw new IllegalArgumentException("center cannot be null");
5474
}
55-
5675
if (radius <= 0) {
5776
throw new IllegalArgumentException("Radius must be greater than 0");
5877
}
@@ -92,6 +111,11 @@ public void cloneFields(Cloner cloner, Object original) {
92111
this.center = cloner.clone(center);
93112
}
94113

114+
/**
115+
* Generates a random point within the volume of the sphere.
116+
*
117+
* @param store The {@link Vector3f} to store the generated point in.
118+
*/
95119
@Override
96120
public void getRandomPoint(Vector3f store) {
97121
do {
@@ -103,23 +127,50 @@ public void getRandomPoint(Vector3f store) {
103127
store.addLocal(center);
104128
}
105129

130+
/**
131+
* For a sphere shape, the normal is not well-defined for points within the volume.
132+
* This implementation simply calls {@link #getRandomPoint(Vector3f)} and does not modify the provided normal.
133+
*
134+
* @param store The {@link Vector3f} to store the generated point in.
135+
* @param normal The {@link Vector3f} to store the generated normal in (unused).
136+
*/
106137
@Override
107138
public void getRandomPointAndNormal(Vector3f store, Vector3f normal) {
108139
this.getRandomPoint(store);
109140
}
110141

142+
/**
143+
* Returns the center point of the sphere.
144+
*
145+
* @return The center point.
146+
*/
111147
public Vector3f getCenter() {
112148
return center;
113149
}
114150

151+
/**
152+
* Sets the center point of the sphere.
153+
*
154+
* @param center The new center point.
155+
*/
115156
public void setCenter(Vector3f center) {
116157
this.center = center;
117158
}
118159

160+
/**
161+
* Returns the radius of the sphere.
162+
*
163+
* @return The radius.
164+
*/
119165
public float getRadius() {
120166
return radius;
121167
}
122168

169+
/**
170+
* Sets the radius of the sphere.
171+
*
172+
* @param radius The new radius.
173+
*/
123174
public void setRadius(float radius) {
124175
this.radius = radius;
125176
}

0 commit comments

Comments
 (0)