Skip to content

Commit 1d20091

Browse files
authored
MatParamTexture: duplicate variables, missing javadoc, exceptions (#2243)
* MatParamTexture: duplicate variables, missing javadoc, setValue to null throws exception This PR solves all the problems listed above. * removal of setValue() override method * javadoc
1 parent 76d8a43 commit 1d20091

File tree

1 file changed

+40
-24
lines changed

1 file changed

+40
-24
lines changed

jme3-core/src/main/java/com/jme3/material/MatParamTexture.java

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2021 jMonkeyEngine
2+
* Copyright (c) 2009-2024 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -40,51 +40,67 @@
4040
import com.jme3.texture.image.ColorSpace;
4141
import java.io.IOException;
4242

43+
/**
44+
* A material parameter that holds a reference to a texture and its required color space.
45+
* This class extends {@link MatParam} to provide texture specific functionalities.
46+
*/
4347
public class MatParamTexture extends MatParam {
4448

45-
private Texture texture;
4649
private ColorSpace colorSpace;
4750

51+
/**
52+
* Constructs a new MatParamTexture instance with the specified type, name,
53+
* texture, and color space.
54+
*
55+
* @param type the type of the material parameter
56+
* @param name the name of the parameter
57+
* @param texture the texture associated with this parameter
58+
* @param colorSpace the required color space for the texture
59+
*/
4860
public MatParamTexture(VarType type, String name, Texture texture, ColorSpace colorSpace) {
4961
super(type, name, texture);
50-
this.texture = texture;
5162
this.colorSpace = colorSpace;
5263
}
5364

65+
/**
66+
* Serialization only. Do not use.
67+
*/
5468
public MatParamTexture() {
5569
}
5670

71+
/**
72+
* Retrieves the texture associated with this material parameter.
73+
*
74+
* @return the texture object
75+
*/
5776
public Texture getTextureValue() {
58-
return texture;
77+
return (Texture) getValue();
5978
}
6079

80+
/**
81+
* Sets the texture associated with this material parameter.
82+
*
83+
* @param value the texture object to set
84+
* @throws RuntimeException if the provided value is not a {@link Texture}
85+
*/
6186
public void setTextureValue(Texture value) {
62-
this.value = value;
63-
this.texture = value;
64-
}
65-
66-
@Override
67-
public void setValue(Object value) {
68-
if (!(value instanceof Texture)) {
69-
throw new IllegalArgumentException("value must be a texture object");
70-
}
71-
this.value = value;
72-
this.texture = (Texture) value;
87+
setValue(value);
7388
}
7489

7590
/**
91+
* Gets the required color space for this texture parameter.
7692
*
77-
* @return the color space required by this texture param
93+
* @return the required color space ({@link ColorSpace})
7894
*/
7995
public ColorSpace getColorSpace() {
8096
return colorSpace;
8197
}
8298

8399
/**
84-
* Set to {@link ColorSpace#Linear} if the texture color space has to be forced to linear
85-
* instead of sRGB
100+
* Set to {@link ColorSpace#Linear} if the texture color space has to be forced
101+
* to linear instead of sRGB.
102+
*
86103
* @param colorSpace the desired color space
87-
* @see ColorSpace
88104
*/
89105
public void setColorSpace(ColorSpace colorSpace) {
90106
this.colorSpace = colorSpace;
@@ -94,17 +110,17 @@ public void setColorSpace(ColorSpace colorSpace) {
94110
public void write(JmeExporter ex) throws IOException {
95111
super.write(ex);
96112
OutputCapsule oc = ex.getCapsule(this);
97-
oc.write(0, "texture_unit", -1);
98-
oc.write(texture, "texture", null); // For backwards compatibility
99-
100113
oc.write(colorSpace, "colorSpace", null);
114+
// For backwards compatibility
115+
oc.write(0, "texture_unit", -1);
116+
oc.write((Texture) value, "texture", null);
101117
}
102118

103119
@Override
104120
public void read(JmeImporter im) throws IOException {
105121
super.read(im);
106122
InputCapsule ic = im.getCapsule(this);
107-
texture = (Texture) value;
108123
colorSpace = ic.readEnum("colorSpace", ColorSpace.class, null);
109124
}
110-
}
125+
126+
}

0 commit comments

Comments
 (0)