|
|
|
@ -62,26 +62,26 @@ import com.jme3.texture.Texture.WrapMode; |
|
|
|
|
import com.jme3.util.BufferUtils; |
|
|
|
|
|
|
|
|
|
public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
|
|
|
|
|
private static final Logger LOGGER = Logger.getLogger(MaterialHelper.class.getName()); |
|
|
|
|
protected static final float DEFAULT_SHININESS = 20.0f; |
|
|
|
|
|
|
|
|
|
public static final String TEXTURE_TYPE_COLOR = "ColorMap"; |
|
|
|
|
public static final String TEXTURE_TYPE_DIFFUSE = "DiffuseMap"; |
|
|
|
|
public static final String TEXTURE_TYPE_NORMAL = "NormalMap"; |
|
|
|
|
public static final String TEXTURE_TYPE_SPECULAR = "SpecularMap"; |
|
|
|
|
public static final String TEXTURE_TYPE_GLOW = "GlowMap"; |
|
|
|
|
public static final String TEXTURE_TYPE_ALPHA = "AlphaMap"; |
|
|
|
|
|
|
|
|
|
public static final Integer ALPHA_MASK_NONE = Integer.valueOf(0); |
|
|
|
|
public static final Integer ALPHA_MASK_CIRCLE = Integer.valueOf(1); |
|
|
|
|
public static final Integer ALPHA_MASK_CONE = Integer.valueOf(2); |
|
|
|
|
public static final Integer ALPHA_MASK_HYPERBOLE = Integer.valueOf(3); |
|
|
|
|
protected final Map<Integer, AlphaMask> alphaMasks = new HashMap<Integer, AlphaMask>(); |
|
|
|
|
protected final Map<Integer, IAlphaMask> alphaMasks = new HashMap<Integer, IAlphaMask>(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The type of the material's diffuse shader. |
|
|
|
|
*/ |
|
|
|
|
public static enum DiffuseShader { |
|
|
|
|
|
|
|
|
|
LAMBERT, ORENNAYAR, TOON, MINNAERT, FRESNEL |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -89,9 +89,9 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
* The type of the material's specular shader. |
|
|
|
|
*/ |
|
|
|
|
public static enum SpecularShader { |
|
|
|
|
|
|
|
|
|
COOKTORRENCE, PHONG, BLINN, TOON, WARDISO |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Face cull mode. Should be excplicitly set before this helper is used. */ |
|
|
|
|
protected FaceCullMode faceCullMode; |
|
|
|
|
|
|
|
|
@ -105,19 +105,16 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
public MaterialHelper(String blenderVersion) { |
|
|
|
|
super(blenderVersion); |
|
|
|
|
// setting alpha masks
|
|
|
|
|
alphaMasks.put(ALPHA_MASK_NONE, new AlphaMask() { |
|
|
|
|
|
|
|
|
|
alphaMasks.put(ALPHA_MASK_NONE, new IAlphaMask() { |
|
|
|
|
@Override |
|
|
|
|
public void setImageSize(int width, int height) { |
|
|
|
|
} |
|
|
|
|
public void setImageSize(int width, int height) {} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public byte getAlpha(float x, float y) { |
|
|
|
|
return (byte) 255; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
alphaMasks.put(ALPHA_MASK_CIRCLE, new AlphaMask() { |
|
|
|
|
|
|
|
|
|
alphaMasks.put(ALPHA_MASK_CIRCLE, new IAlphaMask() { |
|
|
|
|
private float r; |
|
|
|
|
private float[] center; |
|
|
|
|
|
|
|
|
@ -133,8 +130,7 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
return (byte) (d >= r ? 0 : 255); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
alphaMasks.put(ALPHA_MASK_CONE, new AlphaMask() { |
|
|
|
|
|
|
|
|
|
alphaMasks.put(ALPHA_MASK_CONE, new IAlphaMask() { |
|
|
|
|
private float r; |
|
|
|
|
private float[] center; |
|
|
|
|
|
|
|
|
@ -150,8 +146,7 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
return (byte) (d >= r ? 0 : -255.0f * d / r + 255.0f); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
alphaMasks.put(ALPHA_MASK_HYPERBOLE, new AlphaMask() { |
|
|
|
|
|
|
|
|
|
alphaMasks.put(ALPHA_MASK_HYPERBOLE, new IAlphaMask() { |
|
|
|
|
private float r; |
|
|
|
|
private float[] center; |
|
|
|
|
|
|
|
|
@ -210,11 +205,7 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
String name = structure.getName(); |
|
|
|
|
LOGGER.log(Level.INFO, "Material's name: {0}", name); |
|
|
|
|
if (vertexColor) { |
|
|
|
|
if (shadeless) { |
|
|
|
|
result.setBoolean("VertexColor", true); |
|
|
|
|
} else { |
|
|
|
|
result.setBoolean("UseVertexColor", true); |
|
|
|
|
} |
|
|
|
|
result.setBoolean(shadeless ? "VertexColor" : "UseVertexColor", true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); |
|
|
|
@ -222,7 +213,7 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
if (shadeless) { |
|
|
|
|
// color of shadeless? doesn't seem to work in blender ..
|
|
|
|
|
} else { |
|
|
|
|
result.setBoolean("UseMaterialColors", true); |
|
|
|
|
result.setBoolean("UseMaterialColors", Boolean.TRUE); |
|
|
|
|
|
|
|
|
|
// setting the colors
|
|
|
|
|
DiffuseShader diffuseShader = materialHelper.getDiffuseShader(structure); |
|
|
|
@ -260,10 +251,7 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
Texture texture = textureHelper.getTexture(tex, dataRepository); |
|
|
|
|
if (texture != null) { |
|
|
|
|
if ((mapto & 0x01) != 0) {// Col
|
|
|
|
|
if (!shadeless){ |
|
|
|
|
result.setBoolean("UseMaterialColors", false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result.setBoolean("UseMaterialColors", Boolean.FALSE); |
|
|
|
|
// blending the texture with material color and texture's defined color
|
|
|
|
|
int blendType = ((Number) textureLink.getFieldValue("blendtype")).intValue(); |
|
|
|
|
float[] color = new float[] { ((Number) textureLink.getFieldValue("r")).floatValue(), ((Number) textureLink.getFieldValue("g")).floatValue(), ((Number) textureLink.getFieldValue("b")).floatValue() }; |
|
|
|
@ -278,8 +266,11 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
} |
|
|
|
|
if ((mapto & 0x02) != 0) {// Nor
|
|
|
|
|
result.setTexture(TEXTURE_TYPE_NORMAL, texture); |
|
|
|
|
if (vertexColor) { |
|
|
|
|
result.setBoolean(shadeless ? "VertexColor" : "UseVertexColor", false); |
|
|
|
|
} |
|
|
|
|
if ((mapto & 0x20) != 0) {// Spec
|
|
|
|
|
} |
|
|
|
|
if ((mapto & 0x04) != 0) {// Spec
|
|
|
|
|
result.setTexture(TEXTURE_TYPE_SPECULAR, texture); |
|
|
|
|
} |
|
|
|
|
if ((mapto & 0x40) != 0) {// Emit
|
|
|
|
@ -376,7 +367,7 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
int w = image.getWidth(); |
|
|
|
|
int h = image.getHeight(); |
|
|
|
|
ByteBuffer bb = BufferUtils.createByteBuffer(w * h * 4); |
|
|
|
|
AlphaMask iAlphaMask = alphaMasks.get(alphaMaskIndex); |
|
|
|
|
IAlphaMask iAlphaMask = alphaMasks.get(alphaMaskIndex); |
|
|
|
|
iAlphaMask.setImageSize(w, h); |
|
|
|
|
|
|
|
|
|
for (int x = 0; x < w; ++x) { |
|
|
|
@ -686,8 +677,7 @@ public class MaterialHelper extends AbstractBlenderHelper { |
|
|
|
|
* An interface used in calculating alpha mask during particles' texture calculations. |
|
|
|
|
* @author Marcin Roguski (Kaelthas) |
|
|
|
|
*/ |
|
|
|
|
protected static interface AlphaMask { |
|
|
|
|
|
|
|
|
|
protected static interface IAlphaMask { |
|
|
|
|
/** |
|
|
|
|
* This method sets the size of the texture's image. |
|
|
|
|
* @param width |
|
|
|
|