Skip to content

Commit 0bd6d6b

Browse files
Merge pull request #39 from ArtifactForms/working
Merge Working Branch
2 parents 3df0638 + d570871 commit 0bd6d6b

File tree

73 files changed

+5144
-2880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+5144
-2880
lines changed

src/main/java/mesh/modifier/BevelVerticesModifier.java

Lines changed: 238 additions & 85 deletions
Large diffs are not rendered by default.
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
package scene.light;
2+
3+
import math.Color;
4+
import math.Vector3f;
5+
6+
/**
7+
* Represents a directional light source in a 3D scene.
8+
*
9+
* <p>
10+
* A directional light simulates light emitted from a distant source, such as
11+
* the sun or moon. Unlike point lights or spotlights, directional lights have
12+
* no specific position, and their light rays travel in a uniform direction
13+
* throughout the scene. This makes them ideal for creating consistent lighting
14+
* over large areas.
15+
* </p>
16+
*
17+
* <pre>
18+
* Key characteristics of a directional light:
19+
* - The light's direction is defined by a normalized vector.
20+
* - It emits light uniformly in the specified direction, without attenuation
21+
* (intensity does not decrease with distance).
22+
* - It is commonly used to simulate natural light sources like sunlight during
23+
* the day or moonlight at night.
24+
* </pre>
25+
*
26+
* This class provides methods to configure the light's direction, color, and
27+
* intensity, as well as integration with rendering systems via the
28+
* {@link LightRenderer}.
29+
*/
30+
public class DirectionalLight implements Light {
31+
32+
/**
33+
* The color of the light emitted by the directional light source.
34+
*/
35+
private Color color;
36+
37+
/**
38+
* The direction of the light source.
39+
*/
40+
private Vector3f direction;
41+
42+
/**
43+
* The intensity of the light emitted by the directional light source.
44+
*/
45+
private float intensity;
46+
47+
/**
48+
* Creates a new DirectionalLight instance with default settings.
49+
*
50+
* <p>
51+
* This constructor initializes the light with the following defaults: -
52+
* Color: White light. RGB(255, 255, 255) - Direction: A downward-facing
53+
* vector (0, 1, 0), simulating overhead light. - Intensity: 1.0 (full
54+
* strength).
55+
* </p>
56+
*/
57+
public DirectionalLight() {
58+
this(Color.WHITE, new Vector3f(0, 1, 0), 1.0f);
59+
}
60+
61+
/**
62+
* Creates a new DirectionalLight instance.
63+
*
64+
* @param color The color of the light emitted by the directional light
65+
* source. Represents the RGB values of the light's color.
66+
* This parameter cannot be null.
67+
* @param direction The direction of the light source. This vector determines
68+
* the direction in which the light rays travel. The provided
69+
* vector is automatically normalized during construction,
70+
* ensuring the direction's magnitude is always 1. This
71+
* parameter cannot be null.
72+
* @param intensity The intensity of the light emitted by the directional
73+
* light source. This value must be non-negative.
74+
*
75+
* @throws IllegalArgumentException if the direction or color is null, or if
76+
* the intensity is negative.
77+
*/
78+
public DirectionalLight(Color color, Vector3f direction, float intensity) {
79+
setColor(color);
80+
setDirection(direction);
81+
setIntensity(intensity);
82+
}
83+
84+
/**
85+
* Gets the direction of the light source.
86+
*
87+
* @return The direction of the light source.
88+
* @see #setDirection(Vector3f)
89+
*/
90+
public Vector3f getDirection() {
91+
return direction;
92+
}
93+
94+
/**
95+
* Sets the direction of the directional light source.
96+
*
97+
* The provided vector is normalized to ensure the light's direction always
98+
* has a magnitude of 1, which maintains consistent light behavior. This
99+
* method validates that the input is not null to avoid runtime errors.
100+
*
101+
* @param direction The new direction vector for the light source. This vector
102+
* defines the direction in which the light rays travel.
103+
*
104+
* @throws IllegalArgumentException if the provided direction vector is null.
105+
*/
106+
public void setDirection(Vector3f direction) {
107+
if (direction == null)
108+
throw new IllegalArgumentException("Direction cannot be null.");
109+
this.direction = direction.normalize();
110+
}
111+
112+
/**
113+
* Gets the color of the light emitted by the directional light source.
114+
*
115+
* @return The color of the light.
116+
* @see #setColor(Color)
117+
*/
118+
@Override
119+
public Color getColor() {
120+
return color;
121+
}
122+
123+
/**
124+
* Sets the color of the directional light source.
125+
*
126+
* This method updates the light's emitted color. It validates that the
127+
* provided color is not null to ensure the light's color is always valid.
128+
*
129+
* @param color The new color of the light to set. Represents the RGB values
130+
* of the light's color.
131+
*
132+
* @throws IllegalArgumentException if the provided color is null.
133+
*/
134+
public void setColor(Color color) {
135+
if (color == null)
136+
throw new IllegalArgumentException("Color cannot be null.");
137+
this.color = color;
138+
}
139+
140+
/**
141+
* Gets the intensity of the light emitted by the directional light source.
142+
*
143+
* @return The intensity of the light.
144+
* @see #setIntensity(float)
145+
*/
146+
public float getIntensity() {
147+
return intensity;
148+
}
149+
150+
/**
151+
* Sets the intensity of the light emitted by the directional light source.
152+
*
153+
* The intensity value determines how bright the light appears in the scene.
154+
* This method ensures that the value is non-negative, as negative intensity
155+
* does not make logical sense in this context.
156+
*
157+
* @param intensity The new intensity value to set for the light source. Must
158+
* be non-negative to represent valid light brightness.
159+
*
160+
* @throws IllegalArgumentException if the provided intensity is negative.
161+
*/
162+
public void setIntensity(float intensity) {
163+
if (intensity < 0)
164+
throw new IllegalArgumentException("Intensity must be non-negative.");
165+
this.intensity = intensity;
166+
}
167+
168+
/**
169+
* Gets the type of the light source.
170+
*
171+
* @return The type of the light source, which is `LightType.DIRECTIONAL`.
172+
*/
173+
@Override
174+
public LightType getType() {
175+
return LightType.DIRECTIONAL;
176+
}
177+
178+
/**
179+
* Renders the directional light source using the provided renderer.
180+
*
181+
* @param renderer The renderer to use for rendering the light source.
182+
*/
183+
@Override
184+
public void render(LightRenderer renderer) {
185+
renderer.render(this);
186+
}
187+
188+
/**
189+
* Provides a string representation of this directional light instance for
190+
* debugging.
191+
*
192+
* @return String describing the current state of the directional light.
193+
*/
194+
@Override
195+
public String toString() {
196+
return "DirectionalLight [color=" + color + ", direction=" + direction
197+
+ ", intensity=" + intensity + "]";
198+
}
199+
200+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package scene.light;
2+
3+
import math.Color;
4+
5+
/**
6+
* Interface for defining light sources within a 3D scene.
7+
*
8+
* <p>
9+
* This interface serves as a contract for all light types (e.g., PointLight,
10+
* DirectionalLight, SpotLight) by defining essential behaviors and properties
11+
* that any light source should possess. It provides mechanisms to query a
12+
* light's type, retrieve its color, and delegate rendering logic to a given
13+
* renderer.
14+
* </p>
15+
*/
16+
public interface Light {
17+
18+
/**
19+
* Gets the color of the light emitted by the light source.
20+
*
21+
* @return The {@link Color} object representing the light's color. The color
22+
* should define the RGB components that determine the light's hue and
23+
* saturation.
24+
*/
25+
Color getColor();
26+
27+
/**
28+
* Gets the type of the light source.
29+
*
30+
* @return The {@link LightType} that identifies the specific type of light
31+
* (e.g., POINT, DIRECTIONAL, or SPOT) this instance represents.
32+
*/
33+
LightType getType();
34+
35+
/**
36+
* Gets the light source using the provided renderer to draw the light's
37+
* effects.
38+
*
39+
* This method allows the implementation to delegate rendering logic to the
40+
* given {@link LightRenderer}. The rendering logic could involve adding
41+
* effects like shadows, light rays, or other visual representations specific
42+
* to the light's type.
43+
*
44+
* @param renderer The {@link LightRenderer} implementation responsible for
45+
* rendering this light's effects in the scene.
46+
*/
47+
void render(LightRenderer renderer);
48+
49+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package scene.light;
2+
3+
/**
4+
* Interface for rendering various light sources in a 3D scene.
5+
* <p>
6+
* This interface establishes a contract for rendering different types of light
7+
* sources in a 3D environment. It provides specific rendering methods for each
8+
* type of light, such as {@link PointLight}, {@link DirectionalLight}, and
9+
* {@link SpotLight}. Implementations of this interface handle the actual
10+
* rendering logic for these light types within a 3D graphics or game engine.
11+
* </p>
12+
*/
13+
public interface LightRenderer {
14+
15+
/**
16+
* Renders a generic light source.
17+
* <p>
18+
* This method is a catch-all for rendering any light source that implements
19+
* the {@link Light} interface. Specific rendering logic for the light type
20+
* may be determined by the implementation.
21+
* </p>
22+
*
23+
* @param light The light source to render. Must not be null.
24+
*/
25+
void render(Light light);
26+
27+
/**
28+
* Renders a spotlight.
29+
* <p>
30+
* This method is responsible for rendering a spotlight with specific
31+
* directionality, cone angles, and attenuation effects. Spotlights are used
32+
* to simulate focused beams of light, such as those from flashlights, lamps,
33+
* or theater lighting.
34+
* </p>
35+
*
36+
* @param light The spotlight to render. Must not be null.
37+
*/
38+
void render(SpotLight light);
39+
40+
/**
41+
* Renders a point light source.
42+
* <p>
43+
* This method handles the rendering of a point light, which emits light
44+
* uniformly in all directions from a single point in 3D space. Point lights
45+
* are commonly used to simulate small localized light sources such as light
46+
* bulbs or torches.
47+
* </p>
48+
*
49+
* @param light The point light source to render. Must not be null.
50+
*/
51+
void render(PointLight light);
52+
53+
/**
54+
* Renders a directional light source.
55+
* <p>
56+
* This method handles rendering for a directional light, which simulates
57+
* light coming from a distant, uniform direction (e.g., sunlight or
58+
* moonlight). Directional lights are ideal for simulating natural light
59+
* sources that do not have an attenuation effect based on distance.
60+
* </p>
61+
*
62+
* @param light The directional light source to render. Must not be null.
63+
*/
64+
void render(DirectionalLight light);
65+
66+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package scene.light;
2+
3+
/**
4+
* Enum representing different types of lights.
5+
*
6+
* This enum defines the three primary types of lights commonly used in 3D
7+
* graphics:
8+
*
9+
* <pre>
10+
* - POINT: A point light emits light uniformly in all directions.
11+
* - DIRECTIONAL: A directional light emits light in parallel rays from
12+
* a specific direction.
13+
* - SPOT: A spotlight emits light in a cone shape, with a specific
14+
* direction and angle.
15+
* </pre>
16+
*/
17+
public enum LightType {
18+
19+
POINT, DIRECTIONAL, SPOT
20+
21+
}

0 commit comments

Comments
 (0)