Javadocs added and removed unused methods.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7566 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 14 years ago
parent c6be5633ce
commit c4270ad91f
  1. 94
      engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MaterialHelper.java

@ -40,7 +40,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme3.asset.BlenderKey.FeaturesToLoad;
import com.jme3.asset.TextureKey;
import com.jme3.material.MatParam;
import com.jme3.material.Material;
import com.jme3.material.Material.MatParamTexture;
@ -105,14 +104,14 @@ public class MaterialHelper extends AbstractBlenderHelper {
*/
public MaterialHelper(String blenderVersion) {
super(blenderVersion);
//setting alpha masks
// setting alpha masks
alphaMasks.put(ALPHA_MASK_NONE, new IAlphaMask() {
@Override
public void setImageSize(int width, int height) {}
@Override
public byte getAlpha(float x, float y) {
return (byte)255;
return (byte) 255;
}
});
alphaMasks.put(ALPHA_MASK_CIRCLE, new IAlphaMask() {
@ -122,13 +121,13 @@ public class MaterialHelper extends AbstractBlenderHelper {
@Override
public void setImageSize(int width, int height) {
r = Math.min(width, height) * 0.5f;
center = new float[] {width*0.5f, height * 0.5f};
center = new float[] { width * 0.5f, height * 0.5f };
}
@Override
public byte getAlpha(float x, float y) {
float d = FastMath.abs(FastMath.sqrt((x-center[0])*(x-center[0]) + (y-center[1])*(y-center[1])));
return (byte)(d>=r ? 0 : 255);
float d = FastMath.abs(FastMath.sqrt((x - center[0]) * (x - center[0]) + (y - center[1]) * (y - center[1])));
return (byte) (d >= r ? 0 : 255);
}
});
alphaMasks.put(ALPHA_MASK_CONE, new IAlphaMask() {
@ -138,13 +137,13 @@ public class MaterialHelper extends AbstractBlenderHelper {
@Override
public void setImageSize(int width, int height) {
r = Math.min(width, height) * 0.5f;
center = new float[] {width*0.5f, height * 0.5f};
center = new float[] { width * 0.5f, height * 0.5f };
}
@Override
public byte getAlpha(float x, float y) {
float d = FastMath.abs(FastMath.sqrt((x-center[0])*(x-center[0]) + (y-center[1])*(y-center[1])));
return (byte)(d>=r ? 0 : -255.0f*d/r+255.0f);
float d = FastMath.abs(FastMath.sqrt((x - center[0]) * (x - center[0]) + (y - center[1]) * (y - center[1])));
return (byte) (d >= r ? 0 : -255.0f * d / r + 255.0f);
}
});
alphaMasks.put(ALPHA_MASK_HYPERBOLE, new IAlphaMask() {
@ -154,13 +153,13 @@ public class MaterialHelper extends AbstractBlenderHelper {
@Override
public void setImageSize(int width, int height) {
r = Math.min(width, height) * 0.5f;
center = new float[] {width*0.5f, height * 0.5f};
center = new float[] { width * 0.5f, height * 0.5f };
}
@Override
public byte getAlpha(float x, float y) {
float d = FastMath.abs(FastMath.sqrt((x-center[0])*(x-center[0]) + (y-center[1])*(y-center[1]))) / r;
return d>=1.0f ? 0 : (byte)((-FastMath.sqrt((2.0f-d)*d)+1.0f)*255.0f);
float d = FastMath.abs(FastMath.sqrt((x - center[0]) * (x - center[0]) + (y - center[1]) * (y - center[1]))) / r;
return d >= 1.0f ? 0 : (byte) ((-FastMath.sqrt((2.0f - d) * d) + 1.0f) * 255.0f);
}
});
}
@ -244,9 +243,9 @@ public class MaterialHelper extends AbstractBlenderHelper {
List<Structure> mtex = p.fetchData(dataRepository.getInputStream());
if (mtex.size() == 1) {
Structure textureLink = mtex.get(0);
int texflag = ((Number)textureLink.getFieldValue("texflag")).intValue();
//int texco = ((Number) textureLink.getFieldValue("texco")).intValue();
boolean negateTexture = (texflag & 0x04)==0;
int texflag = ((Number) textureLink.getFieldValue("texflag")).intValue();
// int texco = ((Number) textureLink.getFieldValue("texco")).intValue();
boolean negateTexture = (texflag & 0x04) == 0;
// if(texco == 0x10) {//TEXCO_UV (this is only supported now)
int mapto = ((Number) textureLink.getFieldValue("mapto")).intValue();
@ -259,12 +258,9 @@ public class MaterialHelper extends AbstractBlenderHelper {
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() };
float[] color = new float[] { ((Number) textureLink.getFieldValue("r")).floatValue(), ((Number) textureLink.getFieldValue("g")).floatValue(), ((Number) textureLink.getFieldValue("b")).floatValue() };
float colfac = ((Number) textureLink.getFieldValue("colfac")).floatValue();
texture = textureHelper.blendTexture(diffuseColor.getColorArray(), texture, color, colfac, blendType,
negateTexture, dataRepository);
texture = textureHelper.blendTexture(diffuseColor.getColorArray(), texture, color, colfac, blendType, negateTexture, dataRepository);
texture.setWrap(WrapMode.Repeat);
if (shadeless) {
result.setTexture(TEXTURE_TYPE_COLOR, texture);
@ -315,8 +311,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
* @return material without textures of a specified type
*/
public Material getNonTexturedMaterial(Material material, int imageType) {
String[] textureParamNames = new String[] { TEXTURE_TYPE_DIFFUSE, TEXTURE_TYPE_NORMAL, TEXTURE_TYPE_GLOW, TEXTURE_TYPE_SPECULAR,
TEXTURE_TYPE_ALPHA };
String[] textureParamNames = new String[] { TEXTURE_TYPE_DIFFUSE, TEXTURE_TYPE_NORMAL, TEXTURE_TYPE_GLOW, TEXTURE_TYPE_SPECULAR, TEXTURE_TYPE_ALPHA };
Map<String, Texture> textures = new HashMap<String, Texture>(textureParamNames.length);
for (String textureParamName : textureParamNames) {
MatParamTexture matParamTexture = material.getTextureParam(textureParamName);
@ -336,8 +331,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
material.clearParam(textureParamName.getKey());
}
} catch (NumberFormatException e) {
LOGGER.log(Level.WARNING, "The name of the texture does not contain the texture type value! {0} will not be removed!",
name);
LOGGER.log(Level.WARNING, "The name of the texture does not contain the texture type value! {0} will not be removed!", name);
}
}
Material result = material.clone();
@ -353,19 +347,21 @@ public class MaterialHelper extends AbstractBlenderHelper {
* This method converts the given material into particles-usable material.
* The texture and glow color are being copied.
* The method assumes it receives the Lighting type of material.
* @param material the source material
* @param dataRepository the data repository
* @param material
* the source material
* @param dataRepository
* the data repository
* @return material converted into particles-usable material
*/
public Material getParticlesMaterial(Material material, Integer alphaMaskIndex, DataRepository dataRepository) {
Material result = new Material(dataRepository.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
//copying texture
// copying texture
MatParam diffuseMap = material.getParam("DiffuseMap");
if(diffuseMap!=null) {
if (diffuseMap != null) {
Texture texture = ((Texture) diffuseMap.getValue()).clone();
//applying alpha mask to the texture
// applying alpha mask to the texture
Image image = texture.getImage();
ByteBuffer sourceBB = image.getData(0);
sourceBB.rewind();
@ -375,8 +371,8 @@ public class MaterialHelper extends AbstractBlenderHelper {
IAlphaMask iAlphaMask = alphaMasks.get(alphaMaskIndex);
iAlphaMask.setImageSize(w, h);
for(int x=0;x<w;++x) {
for(int y=0;y<h;++y) {
for (int x = 0; x < w; ++x) {
for (int y = 0; y < h; ++y) {
bb.put(sourceBB.get());
bb.put(sourceBB.get());
bb.put(sourceBB.get());
@ -390,24 +386,15 @@ public class MaterialHelper extends AbstractBlenderHelper {
result.setTextureParam("Texture", VarType.Texture2D, texture);
}
//copying glow color
// copying glow color
MatParam glowColor = material.getParam("GlowColor");
if(glowColor!=null) {
if (glowColor != null) {
ColorRGBA color = (ColorRGBA) glowColor.getValue();
result.setParam("GlowColor", VarType.Vector3, color);
}
return result;
}
protected byte calculateAlpha(float x, float y) {
return (byte)255;
}
protected Texture loadParticleAlphaMapTexture(DataRepository dataRepository) {
TextureKey textureKey = new TextureKey(this.getClass().getPackage().getName().replace('.', '/') + "/particle_alpha_map.png");
return dataRepository.getAssetManager().loadTexture(textureKey);
}
/**
* This method indicates if the material has a texture of a specified type.
*
@ -565,8 +552,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
materials = new Material[materialStructures.size()];
int i = 0;
for (Structure s : materialStructures) {
Material material = (Material) dataRepository.getLoadedFeature(s.getOldMemoryAddress(),
LoadedFeatureDataType.LOADED_FEATURE);
Material material = (Material) dataRepository.getLoadedFeature(s.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if (material == null) {
material = materialHelper.toMaterial(s, dataRepository);
}
@ -688,8 +674,28 @@ public class MaterialHelper extends AbstractBlenderHelper {
}
}
/**
* An interface used in calculating alpha mask during particles' texture calculations.
* @author Marcin Roguski (Kaelthas)
*/
protected static interface IAlphaMask {
/**
* This method sets the size of the texture's image.
* @param width
* the width of the image
* @param height
* the height of the image
*/
void setImageSize(int width, int height);
/**
* This method returns the alpha value for the specified texture position.
* @param x
* the X coordinate of the texture position
* @param y
* the Y coordinate of the texture position
* @return the alpha value for the specified texture position
*/
byte getAlpha(float x, float y);
}
}

Loading…
Cancel
Save