1
1
/*
2
- * Copyright (c) 2009-2021 jMonkeyEngine
2
+ * Copyright (c) 2009-2024 jMonkeyEngine
3
3
* All rights reserved.
4
4
*
5
5
* Redistribution and use in source and binary forms, with or without
40
40
import com .jme3 .texture .image .ColorSpace ;
41
41
import java .io .IOException ;
42
42
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
+ */
43
47
public class MatParamTexture extends MatParam {
44
48
45
- private Texture texture ;
46
49
private ColorSpace colorSpace ;
47
50
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
+ */
48
60
public MatParamTexture (VarType type , String name , Texture texture , ColorSpace colorSpace ) {
49
61
super (type , name , texture );
50
- this .texture = texture ;
51
62
this .colorSpace = colorSpace ;
52
63
}
53
64
65
+ /**
66
+ * Serialization only. Do not use.
67
+ */
54
68
public MatParamTexture () {
55
69
}
56
70
71
+ /**
72
+ * Retrieves the texture associated with this material parameter.
73
+ *
74
+ * @return the texture object
75
+ */
57
76
public Texture getTextureValue () {
58
- return texture ;
77
+ return ( Texture ) getValue () ;
59
78
}
60
79
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
+ */
61
86
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 );
73
88
}
74
89
75
90
/**
91
+ * Gets the required color space for this texture parameter.
76
92
*
77
- * @return the color space required by this texture param
93
+ * @return the required color space ({@link ColorSpace})
78
94
*/
79
95
public ColorSpace getColorSpace () {
80
96
return colorSpace ;
81
97
}
82
98
83
99
/**
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
+ *
86
103
* @param colorSpace the desired color space
87
- * @see ColorSpace
88
104
*/
89
105
public void setColorSpace (ColorSpace colorSpace ) {
90
106
this .colorSpace = colorSpace ;
@@ -94,17 +110,17 @@ public void setColorSpace(ColorSpace colorSpace) {
94
110
public void write (JmeExporter ex ) throws IOException {
95
111
super .write (ex );
96
112
OutputCapsule oc = ex .getCapsule (this );
97
- oc .write (0 , "texture_unit" , -1 );
98
- oc .write (texture , "texture" , null ); // For backwards compatibility
99
-
100
113
oc .write (colorSpace , "colorSpace" , null );
114
+ // For backwards compatibility
115
+ oc .write (0 , "texture_unit" , -1 );
116
+ oc .write ((Texture ) value , "texture" , null );
101
117
}
102
118
103
119
@ Override
104
120
public void read (JmeImporter im ) throws IOException {
105
121
super .read (im );
106
122
InputCapsule ic = im .getCapsule (this );
107
- texture = (Texture ) value ;
108
123
colorSpace = ic .readEnum ("colorSpace" , ColorSpace .class , null );
109
124
}
110
- }
125
+
126
+ }
0 commit comments