Skip to content

Commit

Permalink
MatParam: format code (#2202)
Browse files Browse the repository at this point in the history
MatParam: format code

update License year
  • Loading branch information
capdevon authored Feb 29, 2024
1 parent 8181057 commit 52dc934
Showing 1 changed file with 41 additions and 30 deletions.
71 changes: 41 additions & 30 deletions jme3-core/src/main/java/com/jme3/material/MatParam.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 @@ -31,16 +31,26 @@
*/
package com.jme3.material;

import java.io.IOException;
import java.util.Arrays;

import com.jme3.asset.TextureKey;
import com.jme3.export.*;
import com.jme3.math.*;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Matrix3f;
import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector4f;
import com.jme3.shader.VarType;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture.WrapMode;

import java.io.IOException;
import java.util.Arrays;

/**
* Describes a material parameter. This is used for both defining a name and type
* as well as a material parameter value.
Expand All @@ -58,8 +68,8 @@ public class MatParam implements Savable, Cloneable {
/**
* Create a new material parameter. For internal use only.
*
* @param type the type of the parameter
* @param name the desired parameter name
* @param type the type of the parameter
* @param name the desired parameter name
* @param value the desired parameter value (alias created)
*/
public MatParam(VarType type, String name, Object value) {
Expand All @@ -75,20 +85,19 @@ public MatParam(VarType type, String name, Object value) {
protected MatParam() {
}


public boolean isTypeCheckEnabled() {
return typeCheck;
}


/**
* Enable type check for this param.
* When type check is enabled a RuntimeException is thrown if
* an object of the wrong type is passed to setValue.
* @param v (default = true)
*
* @param typeCheck (default = true)
*/
public void setTypeCheckEnabled(boolean v) {
typeCheck = v;
public void setTypeCheckEnabled(boolean typeCheck) {
this.typeCheck = typeCheck;
}

/**
Expand All @@ -102,6 +111,7 @@ public VarType getVarType() {

/**
* Returns the name of the material parameter.
*
* @return the name of the material parameter.
*/
public String getName() {
Expand Down Expand Up @@ -158,15 +168,16 @@ public void setValue(Object value) {
}
}
if (!valid) {
throw new RuntimeException("Trying to assign a value of type " + value.getClass() + " to " + this.getName() + " of type " + type.name() + ". Valid types are "
+ Arrays.deepToString(type.getJavaType()));
throw new RuntimeException("Trying to assign a value of type " + value.getClass()
+ " to " + this.getName()
+ " of type " + type.name()
+ ". Valid types are " + Arrays.deepToString(type.getJavaType()));
}
}
}
this.value = value;
}


/**
* Returns the material parameter value as it would appear in a J3M
* file. E.g.
Expand Down Expand Up @@ -274,35 +285,35 @@ public String getValueAsString() {
case TextureCubeMap:
Texture texVal = (Texture) value;
TextureKey texKey = (TextureKey) texVal.getKey();
if (texKey == null){
//throw new UnsupportedOperationException("The specified MatParam cannot be represented in J3M");
if (texKey == null) {
// throw new UnsupportedOperationException("The specified MatParam cannot be represented in J3M");
// this is used in toString and the above line causes blender materials to throw this exception.
// toStrings should be very robust IMO as even debuggers often invoke toString and logging code
// often does as well, even implicitly.
return texVal+":returned null key";
return texVal + ":returned null key";
}

String ret = "";
if (texKey.isFlipY()) {
ret += "Flip ";
}

//Wrap mode
// Wrap mode
ret += getWrapMode(texVal, Texture.WrapAxis.S);
ret += getWrapMode(texVal, Texture.WrapAxis.T);
ret += getWrapMode(texVal, Texture.WrapAxis.R);

//Min and Mag filter
Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
if(texVal.getImage().hasMipmaps() || texKey.isGenerateMips()){
// Min and Mag filter
Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
if (texVal.getImage().hasMipmaps() || texKey.isGenerateMips()) {
def = Texture.MinFilter.Trilinear;
}
if(texVal.getMinFilter() != def){
ret += "Min" + texVal.getMinFilter().name()+ " ";
if (texVal.getMinFilter() != def) {
ret += "Min" + texVal.getMinFilter().name() + " ";
}

if(texVal.getMagFilter() != Texture.MagFilter.Bilinear){
ret += "Mag" + texVal.getMagFilter().name()+ " ";
if (texVal.getMagFilter() != Texture.MagFilter.Bilinear) {
ret += "Mag" + texVal.getMagFilter().name() + " ";
}

return ret + "\"" + texKey.getName() + "\"";
Expand All @@ -315,12 +326,12 @@ private String getWrapMode(Texture texVal, Texture.WrapAxis axis) {
WrapMode mode = WrapMode.EdgeClamp;
try {
mode = texVal.getWrap(axis);
} catch (IllegalArgumentException e) {
//this axis doesn't exist on the texture
} catch (IllegalArgumentException ex) {
// this axis doesn't exist on the texture
return "";
}
if (mode != WrapMode.EdgeClamp) {
return"Wrap"+ mode.name() + "_" + axis.name() + " ";
return "Wrap" + mode.name() + "_" + axis.name() + " ";
}
return "";
}
Expand Down

0 comments on commit 52dc934

Please sign in to comment.