Skip to content

Commit

Permalink
MatParamTexture: duplicate variables, missing javadoc, exceptions (#2243
Browse files Browse the repository at this point in the history
)

* MatParamTexture: duplicate variables, missing javadoc, setValue to null throws exception

This PR solves all the problems listed above.

* removal of setValue() override method

* javadoc
  • Loading branch information
capdevon authored May 17, 2024
1 parent 76d8a43 commit 1d20091
Showing 1 changed file with 40 additions and 24 deletions.
64 changes: 40 additions & 24 deletions jme3-core/src/main/java/com/jme3/material/MatParamTexture.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2021 jMonkeyEngine
* Copyright (c) 2009-2024 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -40,51 +40,67 @@
import com.jme3.texture.image.ColorSpace;
import java.io.IOException;

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

private Texture texture;
private ColorSpace colorSpace;

/**
* Constructs a new MatParamTexture instance with the specified type, name,
* texture, and color space.
*
* @param type the type of the material parameter
* @param name the name of the parameter
* @param texture the texture associated with this parameter
* @param colorSpace the required color space for the texture
*/
public MatParamTexture(VarType type, String name, Texture texture, ColorSpace colorSpace) {
super(type, name, texture);
this.texture = texture;
this.colorSpace = colorSpace;
}

/**
* Serialization only. Do not use.
*/
public MatParamTexture() {
}

/**
* Retrieves the texture associated with this material parameter.
*
* @return the texture object
*/
public Texture getTextureValue() {
return texture;
return (Texture) getValue();
}

/**
* Sets the texture associated with this material parameter.
*
* @param value the texture object to set
* @throws RuntimeException if the provided value is not a {@link Texture}
*/
public void setTextureValue(Texture value) {
this.value = value;
this.texture = value;
}

@Override
public void setValue(Object value) {
if (!(value instanceof Texture)) {
throw new IllegalArgumentException("value must be a texture object");
}
this.value = value;
this.texture = (Texture) value;
setValue(value);
}

/**
* Gets the required color space for this texture parameter.
*
* @return the color space required by this texture param
* @return the required color space ({@link ColorSpace})
*/
public ColorSpace getColorSpace() {
return colorSpace;
}

/**
* Set to {@link ColorSpace#Linear} if the texture color space has to be forced to linear
* instead of sRGB
* Set to {@link ColorSpace#Linear} if the texture color space has to be forced
* to linear instead of sRGB.
*
* @param colorSpace the desired color space
* @see ColorSpace
*/
public void setColorSpace(ColorSpace colorSpace) {
this.colorSpace = colorSpace;
Expand All @@ -94,17 +110,17 @@ public void setColorSpace(ColorSpace colorSpace) {
public void write(JmeExporter ex) throws IOException {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(0, "texture_unit", -1);
oc.write(texture, "texture", null); // For backwards compatibility

oc.write(colorSpace, "colorSpace", null);
// For backwards compatibility
oc.write(0, "texture_unit", -1);
oc.write((Texture) value, "texture", null);
}

@Override
public void read(JmeImporter im) throws IOException {
super.read(im);
InputCapsule ic = im.getCapsule(this);
texture = (Texture) value;
colorSpace = ic.readEnum("colorSpace", ColorSpace.class, null);
}
}

}

0 comments on commit 1d20091

Please sign in to comment.