aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-extras
diff options
context:
space:
mode:
authorJulien Gouesse <[email protected]>2016-08-17 18:02:22 +0200
committerJulien Gouesse <[email protected]>2016-08-17 18:02:22 +0200
commit7d6d6d8c6fb87487e289ce7eaec423b468d848b5 (patch)
tree005d06e8e6864a03ebf41ff2e898d0a0ee3fd2cb /ardor3d-extras
parentb5e32c8b260cb7bc15c30698763acedf1a4cd75d (diff)
Extracts the most common model properties of a material into a separate class
Diffstat (limited to 'ardor3d-extras')
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjExporter.java107
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java16
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java74
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjMaterial.java82
-rw-r--r--ardor3d-extras/src/main/java/com/ardor3d/extension/model/util/AbstractMaterial.java244
5 files changed, 398 insertions, 125 deletions
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjExporter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjExporter.java
index 83d27c0..2683123 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjExporter.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjExporter.java
@@ -16,7 +16,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.logging.Logger;
@@ -171,42 +170,62 @@ public class ObjExporter {
if (mtlState != null) {
final ReadOnlyColorRGBA ambientColor = mtlState.getAmbient();
if (ambientColor != null) {
- currentMtl.d = ambientColor.getAlpha();
- currentMtl.Ka = new float[] { ambientColor.getRed(), ambientColor.getGreen(),
- ambientColor.getBlue(), ambientColor.getAlpha() };
+ currentMtl.setAmbientRed(ambientColor.getRed());
+ currentMtl.setAmbientGreen(ambientColor.getGreen());
+ currentMtl.setAmbientBlue(ambientColor.getBlue());
+ currentMtl.setAmbientAlpha(ambientColor.getAlpha());
}
final ReadOnlyColorRGBA diffuseColor = mtlState.getDiffuse();
if (diffuseColor != null) {
- currentMtl.Kd = new float[] { diffuseColor.getRed(), diffuseColor.getGreen(),
- diffuseColor.getBlue(), diffuseColor.getAlpha() };
+ currentMtl.setDiffuseRed(diffuseColor.getRed());
+ currentMtl.setDiffuseGreen(diffuseColor.getGreen());
+ currentMtl.setDiffuseBlue(diffuseColor.getBlue());
+ currentMtl.setDiffuseAlpha(diffuseColor.getAlpha());
}
final ReadOnlyColorRGBA specularColor = mtlState.getSpecular();
if (specularColor != null) {
- currentMtl.Ks = new float[] { specularColor.getRed(), specularColor.getGreen(),
- specularColor.getBlue(), specularColor.getAlpha() };
+ currentMtl.setSpecularRed(specularColor.getRed());
+ currentMtl.setSpecularGreen(specularColor.getGreen());
+ currentMtl.setSpecularBlue(specularColor.getBlue());
+ currentMtl.setSpecularAlpha(specularColor.getAlpha());
}
- currentMtl.Ns = mtlState.getShininess();
+ currentMtl.setShininess(mtlState.getShininess());
}
if (customTextureName == null) {
- currentMtl.textureName = getLocalMeshTextureName(mesh);
+ currentMtl.setTextureName(getLocalMeshTextureName(mesh));
} else {
- currentMtl.textureName = customTextureName;
+ currentMtl.setTextureName(customTextureName);
}
if (mesh.getSceneHints().getLightCombineMode() == LightCombineMode.Off) {
// Color on and Ambient off
- currentMtl.illumType = 0;
+ currentMtl.setIllumType(0);
} else {
// Color on and Ambient on
- currentMtl.illumType = 1;
+ currentMtl.setIllumType(1);
}
ObjMaterial sameObjMtl = null;
if (materialList != null && !materialList.isEmpty()) {
for (final ObjMaterial mtl : materialList) {
- if (mtl.illumType == currentMtl.illumType && mtl.Ns == currentMtl.Ns
- && mtl.forceBlend == currentMtl.forceBlend && mtl.d == currentMtl.d
- && Arrays.equals(mtl.Ka, currentMtl.Ka) && Arrays.equals(mtl.Kd, currentMtl.Kd)
- && Arrays.equals(mtl.Ks, currentMtl.Ks)
- && Objects.equals(mtl.textureName, currentMtl.textureName)) {
+ if (mtl.getIllumType() == currentMtl.getIllumType()
+ && mtl.getShininess() == currentMtl.getShininess()
+ && mtl.isForceBlend() == currentMtl.isForceBlend()
+ && mtl.getAmbientRed() == currentMtl.getAmbientRed()
+ && mtl.getAmbientGreen() == currentMtl.getAmbientGreen()
+ && mtl.getAmbientBlue() == currentMtl.getAmbientBlue()
+ && mtl.getAmbientAlpha() == currentMtl.getAmbientAlpha()
+ && mtl.getDiffuseRed() == currentMtl.getDiffuseRed()
+ && mtl.getDiffuseGreen() == currentMtl.getDiffuseGreen()
+ && mtl.getDiffuseBlue() == currentMtl.getDiffuseBlue()
+ && mtl.getDiffuseAlpha() == currentMtl.getDiffuseAlpha()
+ && mtl.getSpecularRed() == currentMtl.getSpecularRed()
+ && mtl.getSpecularGreen() == currentMtl.getSpecularGreen()
+ && mtl.getSpecularBlue() == currentMtl.getSpecularBlue()
+ && mtl.getSpecularAlpha() == currentMtl.getSpecularAlpha()
+ && mtl.getEmissiveRed() == currentMtl.getEmissiveRed()
+ && mtl.getEmissiveGreen() == currentMtl.getEmissiveGreen()
+ && mtl.getEmissiveBlue() == currentMtl.getEmissiveBlue()
+ && mtl.getEmissiveAlpha() == currentMtl.getEmissiveAlpha()
+ && Objects.equals(mtl.getTextureName(), currentMtl.getTextureName())) {
sameObjMtl = mtl;
break;
}
@@ -218,41 +237,39 @@ public class ObjExporter {
+ (materialList == null ? 1 : materialList.size() + 1);
if (materialList != null) {
final ObjMaterial mtl = new ObjMaterial(mtlName);
- mtl.illumType = currentMtl.illumType;
- mtl.textureName = currentMtl.textureName;
+ mtl.setIllumType(currentMtl.getIllumType());
+ mtl.setTextureName(currentMtl.getTextureName());
materialList.add(mtl);
}
mtlPw.println("newmtl " + mtlName);
- if (currentMtl.Ns != -1) {
- mtlPw.println("Ns " + currentMtl.Ns);
+ if (currentMtl.getShininess() != -1) {
+ mtlPw.println("Ns " + currentMtl.getShininess());
}
- if (currentMtl.Ka != null) {
- mtlPw.print("Ka");
- for (final float KaCoef : currentMtl.Ka) {
- mtlPw.print(" " + KaCoef);
- }
- mtlPw.println();
+ if (currentMtl.getAmbientRed() != -1 && currentMtl.getAmbientGreen() != -1
+ && currentMtl.getAmbientBlue() != -1) {
+ mtlPw.println("Ka " + currentMtl.getAmbientRed() + " " + currentMtl.getAmbientGreen() + " "
+ + currentMtl.getAmbientBlue());
}
- if (currentMtl.Kd != null) {
- mtlPw.print("Kd");
- for (final float KdCoef : currentMtl.Kd) {
- mtlPw.print(" " + KdCoef);
- }
- mtlPw.println();
+ if (currentMtl.getDiffuseRed() != -1 && currentMtl.getDiffuseGreen() != -1
+ && currentMtl.getDiffuseBlue() != -1) {
+ mtlPw.println("Kd " + currentMtl.getDiffuseRed() + " " + currentMtl.getDiffuseGreen() + " "
+ + currentMtl.getDiffuseBlue());
}
- if (currentMtl.Ks != null) {
- mtlPw.print("Ks");
- for (final float KsCoef : currentMtl.Ks) {
- mtlPw.print(" " + KsCoef);
- }
- mtlPw.println();
+ if (currentMtl.getSpecularRed() != -1 && currentMtl.getSpecularGreen() != -1
+ && currentMtl.getSpecularBlue() != -1) {
+ mtlPw.println("Ks " + currentMtl.getSpecularRed() + " " + currentMtl.getSpecularGreen()
+ + " " + currentMtl.getSpecularBlue());
}
- if (currentMtl.d != -1) {
- mtlPw.println("d " + currentMtl.d);
+ // exports only a consistent dissolve value when all alpha components are equal
+ if (currentMtl.getAmbientAlpha() != -1
+ && currentMtl.getAmbientAlpha() == currentMtl.getDiffuseAlpha()
+ && currentMtl.getDiffuseAlpha() == currentMtl.getSpecularAlpha()
+ && currentMtl.getSpecularAlpha() == currentMtl.getEmissiveAlpha()) {
+ mtlPw.println("d " + currentMtl.getAmbientAlpha());
}
- mtlPw.println("illum " + currentMtl.illumType);
- if (currentMtl.textureName != null) {
- mtlPw.println("map_Kd " + currentMtl.textureName);
+ mtlPw.println("illum " + currentMtl.getIllumType());
+ if (currentMtl.getTextureName() != null) {
+ mtlPw.println("map_Kd " + currentMtl.getTextureName());
}
} else {
mtlName = sameObjMtl.getName();
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java
index b16acfd..aced00f 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjGeometryStore.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
@@ -192,8 +192,8 @@ public class ObjGeometryStore {
}
final Point points = new Point(name, vertices, null, null, null);
- final IndexBufferData<? extends Buffer> indexBuffer = BufferUtils.createIndexBufferData(_pointManager
- .getIndices().size(), vertices.length - 1);
+ final IndexBufferData<? extends Buffer> indexBuffer = BufferUtils
+ .createIndexBufferData(_pointManager.getIndices().size(), vertices.length - 1);
for (final int index : _pointManager.getIndices()) {
indexBuffer.put(index);
}
@@ -233,8 +233,8 @@ public class ObjGeometryStore {
}
final Line line = new Line(name, vertices, null, null, hasUVs ? uvs : null);
- final IndexBufferData<? extends Buffer> indexBuffer = BufferUtils.createIndexBufferData(_lineManager
- .getIndices().size(), vertices.length - 1);
+ final IndexBufferData<? extends Buffer> indexBuffer = BufferUtils
+ .createIndexBufferData(_lineManager.getIndices().size(), vertices.length - 1);
for (final int index : _lineManager.getIndices()) {
indexBuffer.put(index);
}
@@ -309,8 +309,8 @@ public class ObjGeometryStore {
mesh.getMeshData().setTextureBuffer(uvs, 0);
}
- final IndexBufferData<? extends Buffer> indexBuffer = BufferUtils.createIndexBufferData(_meshManager
- .getIndices().size(), _meshManager.getStore().size() - 1);
+ final IndexBufferData<? extends Buffer> indexBuffer = BufferUtils
+ .createIndexBufferData(_meshManager.getIndices().size(), _meshManager.getStore().size() - 1);
for (final int index : _meshManager.getIndices()) {
indexBuffer.put(index);
}
@@ -356,7 +356,7 @@ public class ObjGeometryStore {
target.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
}
- if (_currentMaterial.illumType == 0) {
+ if (_currentMaterial.getIllumType() == 0) {
target.getSceneHints().setLightCombineMode(LightCombineMode.Off);
}
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java
index 1b141f9..620ae55 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjImporter.java
@@ -419,7 +419,7 @@ public class ObjImporter {
}
/**
- * Load a .mtl resource
+ * Load a .mtl resource, see <a href="http://paulbourke.net/dataformats/mtl/">the format specification</a>
*
* @param resource
* the mtl file to load, as a ResourceSource
@@ -476,62 +476,98 @@ public class ObjImporter {
// if ambient value
if ("Ka".equals(keyword)) {
- currentMaterial.Ka = new float[] { Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]),
- Float.parseFloat(tokens[3]) };
+ currentMaterial.setAmbientRed(Float.parseFloat(tokens[1]));
+ currentMaterial.setAmbientGreen(Float.parseFloat(tokens[2]));
+ currentMaterial.setAmbientBlue(Float.parseFloat(tokens[3]));
}
// if diffuse value
else if ("Kd".equals(keyword)) {
- currentMaterial.Kd = new float[] { Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]),
- Float.parseFloat(tokens[3]) };
+ currentMaterial.setDiffuseRed(Float.parseFloat(tokens[1]));
+ currentMaterial.setDiffuseGreen(Float.parseFloat(tokens[2]));
+ currentMaterial.setDiffuseBlue(Float.parseFloat(tokens[3]));
}
// if specular value
else if ("Ks".equals(keyword)) {
- currentMaterial.Ks = new float[] { Float.parseFloat(tokens[1]), Float.parseFloat(tokens[2]),
- Float.parseFloat(tokens[3]) };
+ currentMaterial.setSpecularRed(Float.parseFloat(tokens[1]));
+ currentMaterial.setSpecularGreen(Float.parseFloat(tokens[2]));
+ currentMaterial.setSpecularBlue(Float.parseFloat(tokens[3]));
+ }
+ // if transmission filter
+ else if ("Tf".equals(keyword)) {
+ // TODO: Add support for Tf
+ }
+ // if sharpness value
+ else if ("sharpness".equals(keyword)) {
+ // TODO: Add support for sharpness
+ }
+ // if optical density
+ else if ("Ni".equals(keyword)) {
+ // TODO: Add support for Ni
+ }
+ // if disp
+ else if ("disp".equals(keyword)) {
+ // TODO: Add support for disp
+ }
+ // if decal value
+ else if ("decal".equals(keyword)) {
+ // TODO: Add support for decal
+ }
+ // if bump
+ else if ("bump".equals(keyword)) {
+ // TODO: Add support for bump
}
-
// if illumination style
else if ("illum".equals(keyword)) {
- currentMaterial.illumType = Integer.parseInt(tokens[1]);
+ currentMaterial.setIllumType(Integer.parseInt(tokens[1]));
}
// if "dissolve" (alpha) value
else if ("d".equals(keyword)) {
- currentMaterial.d = Float.parseFloat(tokens[1]);
+ final float d;
+ if ("-halo".equalsIgnoreCase(tokens[1])) {
+ // TODO: Add support for halo
+ d = Float.parseFloat(tokens[2]);
+ } else {
+ d = Float.parseFloat(tokens[1]);
+ }
+ currentMaterial.setAmbientAlpha(d);
+ currentMaterial.setDiffuseAlpha(d);
+ currentMaterial.setSpecularAlpha(d);
+ currentMaterial.setEmissiveAlpha(d);
}
// if ambient value
else if ("Ns".equals(keyword)) {
final float Ns = Float.parseFloat(tokens[1]);
- currentMaterial.Ns = 128 * MathUtils.clamp(Ns, 0, _specularMax) / _specularMax;
+ currentMaterial.setShininess(128 * MathUtils.clamp(Ns, 0, _specularMax) / _specularMax);
}
// if we mapped a texture to alpha
else if ("map_d".equals(keyword)) {
// force blending... probably also used texture in map_Kd, etc.
- currentMaterial.forceBlend = true;
+ currentMaterial.setForceBlend(true);
}
// if texture
else if (isLoadTextures() && "map_Kd".equals(keyword)) {
// TODO: it's possible for map_Kd to have arguments, then filename.
final String textureName = line.substring("map_Kd".length()).trim();
- currentMaterial.textureName = textureName;
+ currentMaterial.setTextureName(textureName);
if (_textureLocator == null) {
- currentMaterial.map_Kd = TextureManager
- .load(textureName, getMinificationFilter(),
+ currentMaterial
+ .setMap_Kd(TextureManager.load(textureName, getMinificationFilter(),
isUseCompression() ? TextureStoreFormat.GuessCompressedFormat
: TextureStoreFormat.GuessNoCompressedFormat,
- isFlipTextureVertically());
+ isFlipTextureVertically()));
} else {
final ResourceSource source = _textureLocator.locateResource(textureName);
- currentMaterial.map_Kd = TextureManager
- .load(source, getMinificationFilter(),
+ currentMaterial
+ .setMap_Kd(TextureManager.load(source, getMinificationFilter(),
isUseCompression() ? TextureStoreFormat.GuessCompressedFormat
: TextureStoreFormat.GuessNoCompressedFormat,
- isFlipTextureVertically());
+ isFlipTextureVertically()));
}
}
}
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjMaterial.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjMaterial.java
index 3f94f73..ccb8a46 100644
--- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjMaterial.java
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/obj/ObjMaterial.java
@@ -3,52 +3,35 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
package com.ardor3d.extension.model.obj;
+import com.ardor3d.extension.model.util.AbstractMaterial;
import com.ardor3d.image.Texture;
-import com.ardor3d.math.ColorRGBA;
-import com.ardor3d.math.MathUtils;
-import com.ardor3d.renderer.state.BlendState;
-import com.ardor3d.renderer.state.MaterialState;
import com.ardor3d.renderer.state.TextureState;
-public class ObjMaterial {
+/**
+ * WaveFront OBJ material (MTL). <code>Ns</code> matches with the shininess, <code>d</code> matches with the alpha
+ * component(s), <code>Ka</code> matches with the ambient RGB components, <code>Kd</code> matches with the diffuse RGB
+ * components, <code>Ks</code> matches with the specular RGB components.
+ */
+public class ObjMaterial extends AbstractMaterial {
private final String name;
- float[] Ka = null;
- float[] Kd = null;
- float[] Ks = null;
- float Ns = -1;
-
- String textureName;
- Texture map_Kd = null;
+ private String textureName;
- int illumType = 2;
+ private Texture map_Kd;
- boolean forceBlend = false;
- float d = -1;
+ private int illumType;
public ObjMaterial(final String name) {
+ super();
this.name = name;
- }
-
- public BlendState getBlendState() {
- if (forceBlend || d != -1 && d < 1.0f) {
- final BlendState blend = new BlendState();
- blend.setBlendEnabled(true);
- blend.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
- blend.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
- blend.setTestEnabled(true);
- blend.setTestFunction(BlendState.TestFunction.GreaterThan);
- blend.setReference(0);
- return blend;
- }
- return null;
+ illumType = 2;
}
public TextureState getTextureState() {
@@ -60,29 +43,6 @@ public class ObjMaterial {
return null;
}
- public MaterialState getMaterialState() {
- if (Ka != null || Kd != null || Ks != null || d != -1 || Ns != -1) {
- final MaterialState material = new MaterialState();
- final float alpha = d != -1 ? MathUtils.clamp(d, 0, 1) : 1;
- if (Ka != null) {
- material.setAmbient(new ColorRGBA(Ka[0], Ka[1], Ka[2], alpha));
- }
- if (Kd != null) {
- material.setDiffuse(new ColorRGBA(Kd[0], Kd[1], Kd[2], alpha));
- }
- if (Ks != null) {
- material.setSpecular(new ColorRGBA(Ks[0], Ks[1], Ks[2], alpha));
- }
-
- if (Ns != -1) {
- material.setShininess(Ns);
- }
-
- return material;
- }
- return null;
- }
-
public String getName() {
return name;
}
@@ -91,7 +51,23 @@ public class ObjMaterial {
return textureName;
}
+ public void setTextureName(final String textureName) {
+ this.textureName = textureName;
+ }
+
public Texture getMap_Kd() {
return map_Kd;
}
+
+ public void setMap_Kd(final Texture map_Kd) {
+ this.map_Kd = map_Kd;
+ }
+
+ public int getIllumType() {
+ return illumType;
+ }
+
+ public void setIllumType(final int illumType) {
+ this.illumType = illumType;
+ }
}
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/util/AbstractMaterial.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/util/AbstractMaterial.java
new file mode 100644
index 0000000..c008479
--- /dev/null
+++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/util/AbstractMaterial.java
@@ -0,0 +1,244 @@
+/**
+ * Copyright (c) 2008-2014 Ardor Labs, Inc.
+ *
+ * This file is part of Ardor3D.
+ *
+ * Ardor3D is free software: you can redistribute it and/or modify it
+ * under the terms of its license which may be found in the accompanying
+ * LICENSE file or at <http://www.ardor3d.com/LICENSE>.
+ */
+
+package com.ardor3d.extension.model.util;
+
+import com.ardor3d.math.ColorRGBA;
+import com.ardor3d.math.MathUtils;
+import com.ardor3d.renderer.state.BlendState;
+import com.ardor3d.renderer.state.MaterialState;
+
+/**
+ * common material parameters
+ */
+public abstract class AbstractMaterial {
+
+ private float ambientRed, ambientGreen, ambientBlue, ambientAlpha;
+
+ private float diffuseRed, diffuseGreen, diffuseBlue, diffuseAlpha;
+
+ private float emissiveRed, emissiveGreen, emissiveBlue, emissiveAlpha;
+
+ private float specularRed, specularGreen, specularBlue, specularAlpha;
+
+ private float shininess;
+
+ private boolean forceBlend;
+
+ protected AbstractMaterial() {
+ super();
+ ambientRed = -1;
+ ambientGreen = -1;
+ ambientBlue = -1;
+ ambientAlpha = -1;
+ diffuseRed = -1;
+ diffuseGreen = -1;
+ diffuseBlue = -1;
+ diffuseAlpha = -1;
+ emissiveRed = -1;
+ emissiveGreen = -1;
+ emissiveBlue = -1;
+ emissiveAlpha = -1;
+ specularRed = -1;
+ specularGreen = -1;
+ specularBlue = -1;
+ specularAlpha = -1;
+ shininess = -1;
+ }
+
+ public BlendState getBlendState() {
+ if (forceBlend || (ambientAlpha != -1 && ambientAlpha < 1.0f) || (diffuseAlpha != -1 && diffuseAlpha < 1.0f)
+ || (emissiveAlpha != -1 && emissiveAlpha < 1.0f) || (specularAlpha != -1 && specularAlpha < 1.0f)) {
+ final BlendState blend = new BlendState();
+ blend.setBlendEnabled(true);
+ blend.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
+ blend.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
+ blend.setTestEnabled(true);
+ blend.setTestFunction(BlendState.TestFunction.GreaterThan);
+ blend.setReference(0);
+ return blend;
+ }
+ return null;
+ }
+
+ public MaterialState getMaterialState() {
+ if ((ambientRed != -1 && ambientGreen != -1 && ambientBlue != -1)
+ || (diffuseRed != -1 && diffuseGreen != -1 && diffuseBlue != -1)
+ || (emissiveRed != -1 && emissiveGreen != -1 && emissiveBlue != -1)
+ || (specularRed != -1 && specularGreen != -1 && specularBlue != -1) || shininess != -1) {
+ final MaterialState material = new MaterialState();
+ if (ambientRed != -1 && ambientGreen != -1 && ambientBlue != -1) {
+ final float alpha = ambientAlpha == -1 ? 1 : MathUtils.clamp(ambientAlpha, 0, 1);
+ material.setAmbient(new ColorRGBA(ambientRed, ambientGreen, ambientBlue, alpha));
+ }
+ if (diffuseRed != -1 && diffuseGreen != -1 && diffuseBlue != -1) {
+ final float alpha = diffuseAlpha == -1 ? 1 : MathUtils.clamp(diffuseAlpha, 0, 1);
+ material.setDiffuse(new ColorRGBA(diffuseRed, diffuseGreen, diffuseBlue, alpha));
+ }
+ if (emissiveRed != -1 && emissiveGreen != -1 && emissiveBlue != -1) {
+ final float alpha = emissiveAlpha == -1 ? 1 : MathUtils.clamp(emissiveAlpha, 0, 1);
+ material.setEmissive(new ColorRGBA(emissiveRed, emissiveGreen, emissiveBlue, alpha));
+ }
+ if (specularRed != -1 && specularGreen != -1 && specularBlue != -1) {
+ final float alpha = specularAlpha == -1 ? 1 : MathUtils.clamp(specularAlpha, 0, 1);
+ material.setSpecular(new ColorRGBA(specularRed, specularGreen, specularBlue, alpha));
+ }
+ if (shininess != -1) {
+ material.setShininess(shininess);
+ }
+ return material;
+ }
+ return null;
+ }
+
+ public float getAmbientRed() {
+ return ambientRed;
+ }
+
+ public void setAmbientRed(final float ambientRed) {
+ this.ambientRed = ambientRed;
+ }
+
+ public float getAmbientGreen() {
+ return ambientGreen;
+ }
+
+ public void setAmbientGreen(final float ambientGreen) {
+ this.ambientGreen = ambientGreen;
+ }
+
+ public float getAmbientBlue() {
+ return ambientBlue;
+ }
+
+ public void setAmbientBlue(final float ambientBlue) {
+ this.ambientBlue = ambientBlue;
+ }
+
+ public float getDiffuseRed() {
+ return diffuseRed;
+ }
+
+ public void setDiffuseRed(final float diffuseRed) {
+ this.diffuseRed = diffuseRed;
+ }
+
+ public float getDiffuseGreen() {
+ return diffuseGreen;
+ }
+
+ public void setDiffuseGreen(final float diffuseGreen) {
+ this.diffuseGreen = diffuseGreen;
+ }
+
+ public float getDiffuseBlue() {
+ return diffuseBlue;
+ }
+
+ public void setDiffuseBlue(final float diffuseBlue) {
+ this.diffuseBlue = diffuseBlue;
+ }
+
+ public float getEmissiveRed() {
+ return emissiveRed;
+ }
+
+ public void setEmissiveRed(final float emissiveRed) {
+ this.emissiveRed = emissiveRed;
+ }
+
+ public float getEmissiveGreen() {
+ return emissiveGreen;
+ }
+
+ public void setEmissiveGreen(final float emissiveGreen) {
+ this.emissiveGreen = emissiveGreen;
+ }
+
+ public float getEmissiveBlue() {
+ return emissiveBlue;
+ }
+
+ public void setEmissiveBlue(final float emissiveBlue) {
+ this.emissiveBlue = emissiveBlue;
+ }
+
+ public float getSpecularRed() {
+ return specularRed;
+ }
+
+ public void setSpecularRed(final float specularRed) {
+ this.specularRed = specularRed;
+ }
+
+ public float getSpecularGreen() {
+ return specularGreen;
+ }
+
+ public void setSpecularGreen(final float specularGreen) {
+ this.specularGreen = specularGreen;
+ }
+
+ public float getSpecularBlue() {
+ return specularBlue;
+ }
+
+ public void setSpecularBlue(final float specularBlue) {
+ this.specularBlue = specularBlue;
+ }
+
+ public float getAmbientAlpha() {
+ return ambientAlpha;
+ }
+
+ public void setAmbientAlpha(final float ambientAlpha) {
+ this.ambientAlpha = ambientAlpha;
+ }
+
+ public float getDiffuseAlpha() {
+ return diffuseAlpha;
+ }
+
+ public void setDiffuseAlpha(final float diffuseAlpha) {
+ this.diffuseAlpha = diffuseAlpha;
+ }
+
+ public float getEmissiveAlpha() {
+ return emissiveAlpha;
+ }
+
+ public void setEmissiveAlpha(final float emissiveAlpha) {
+ this.emissiveAlpha = emissiveAlpha;
+ }
+
+ public float getSpecularAlpha() {
+ return specularAlpha;
+ }
+
+ public void setSpecularAlpha(final float specularAlpha) {
+ this.specularAlpha = specularAlpha;
+ }
+
+ public float getShininess() {
+ return shininess;
+ }
+
+ public void setShininess(final float shininess) {
+ this.shininess = shininess;
+ }
+
+ public boolean isForceBlend() {
+ return forceBlend;
+ }
+
+ public void setForceBlend(final boolean forceBlend) {
+ this.forceBlend = forceBlend;
+ }
+}