com.jme3.scene.plugins.blender.materials
Class MaterialHelper

java.lang.Object
  extended by com.jme3.scene.plugins.blender.AbstractBlenderHelper
      extended by com.jme3.scene.plugins.blender.materials.MaterialHelper

public class MaterialHelper
extends AbstractBlenderHelper


Nested Class Summary
static class MaterialHelper.DiffuseShader
          The type of the material's diffuse shader.
static class MaterialHelper.SpecularShader
          The type of the material's specular shader.
 
Field Summary
static java.lang.Integer ALPHA_MASK_CIRCLE
           
static java.lang.Integer ALPHA_MASK_CONE
           
static java.lang.Integer ALPHA_MASK_HYPERBOLE
           
static java.lang.Integer ALPHA_MASK_NONE
           
protected  java.util.Map<java.lang.Integer,com.jme3.scene.plugins.blender.materials.IAlphaMask> alphaMasks
           
protected static float DEFAULT_SHININESS
           
static java.lang.String TEXTURE_TYPE_ALPHA
           
static java.lang.String TEXTURE_TYPE_COLOR
           
static java.lang.String TEXTURE_TYPE_DIFFUSE
           
static java.lang.String TEXTURE_TYPE_GLOW
           
static java.lang.String TEXTURE_TYPE_NORMAL
           
static java.lang.String TEXTURE_TYPE_SPECULAR
           
 
Fields inherited from class com.jme3.scene.plugins.blender.AbstractBlenderHelper
blenderVersion, fixUpAxis, upAxisRotationQuaternion
 
Constructor Summary
MaterialHelper(java.lang.String blenderVersion, boolean fixUpAxis)
          This constructor parses the given blender version and stores the result.
 
Method Summary
 MaterialContext[] getMaterials(Structure structureWithMaterials, BlenderContext blenderContext)
          This method returns the table of materials connected to the specified structure.
 Material getNonTexturedMaterial(Material material, int imageType)
          This method returns a material similar to the one given but without textures.
 Material getParticlesMaterial(Material material, java.lang.Integer alphaMaskIndex, BlenderContext blenderContext)
          This method converts the given material into particles-usable material.
 boolean hasTexture(Material material)
          This method indicates if the material has any kind of texture.
 boolean hasTexture(Material material, java.lang.String textureType)
          This method indicates if the material has a texture of a specified type.
 void hsvToRgb(float h, float s, float v, float[] rgb)
          This method converts rgb values to hsv values.
 void rgbToHsv(float r, float g, float b, float[] hsv)
          This method converts rgb values to hsv values.
 boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext)
          This method analyzes the given structure and the data contained within blender context and decides if the feature should be loaded.
 MaterialContext toMaterialContext(Structure structure, BlenderContext blenderContext)
          This method converts the material structure to jme Material.
 
Methods inherited from class com.jme3.scene.plugins.blender.AbstractBlenderHelper
applyProperties, clearState, isBlank, loadProperties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SHININESS

protected static final float DEFAULT_SHININESS
See Also:
Constant Field Values

TEXTURE_TYPE_COLOR

public static final java.lang.String TEXTURE_TYPE_COLOR
See Also:
Constant Field Values

TEXTURE_TYPE_DIFFUSE

public static final java.lang.String TEXTURE_TYPE_DIFFUSE
See Also:
Constant Field Values

TEXTURE_TYPE_NORMAL

public static final java.lang.String TEXTURE_TYPE_NORMAL
See Also:
Constant Field Values

TEXTURE_TYPE_SPECULAR

public static final java.lang.String TEXTURE_TYPE_SPECULAR
See Also:
Constant Field Values

TEXTURE_TYPE_GLOW

public static final java.lang.String TEXTURE_TYPE_GLOW
See Also:
Constant Field Values

TEXTURE_TYPE_ALPHA

public static final java.lang.String TEXTURE_TYPE_ALPHA
See Also:
Constant Field Values

ALPHA_MASK_NONE

public static final java.lang.Integer ALPHA_MASK_NONE

ALPHA_MASK_CIRCLE

public static final java.lang.Integer ALPHA_MASK_CIRCLE

ALPHA_MASK_CONE

public static final java.lang.Integer ALPHA_MASK_CONE

ALPHA_MASK_HYPERBOLE

public static final java.lang.Integer ALPHA_MASK_HYPERBOLE

alphaMasks

protected final java.util.Map<java.lang.Integer,com.jme3.scene.plugins.blender.materials.IAlphaMask> alphaMasks
Constructor Detail

MaterialHelper

public MaterialHelper(java.lang.String blenderVersion,
                      boolean fixUpAxis)
This constructor parses the given blender version and stores the result. Some functionalities may differ in different blender versions.

Parameters:
blenderVersion - the version read from the blend file
fixUpAxis - a variable that indicates if the Y asxis is the UP axis or not
Method Detail

toMaterialContext

public MaterialContext toMaterialContext(Structure structure,
                                         BlenderContext blenderContext)
                                  throws BlenderFileException
This method converts the material structure to jme Material.

Parameters:
structure - structure with material data
blenderContext - the blender context
Returns:
jme material
Throws:
BlenderFileException - an exception is throw when problems with blend file occur

getNonTexturedMaterial

public Material getNonTexturedMaterial(Material material,
                                       int imageType)
This method returns a material similar to the one given but without textures. If the material has no textures it is not cloned but returned itself.

Parameters:
material - a material to be cloned without textures
imageType - type of image defined by blender; the constants are defined in TextureHelper
Returns:
material without textures of a specified type

getParticlesMaterial

public Material getParticlesMaterial(Material material,
                                     java.lang.Integer alphaMaskIndex,
                                     BlenderContext blenderContext)
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.

Parameters:
material - the source material
blenderContext - the blender context
Returns:
material converted into particles-usable material

hasTexture

public boolean hasTexture(Material material)
This method indicates if the material has any kind of texture.

Parameters:
material - the material
Returns:
true if the texture exists in the material and false otherwise

hasTexture

public boolean hasTexture(Material material,
                          java.lang.String textureType)
This method indicates if the material has a texture of a specified type.

Parameters:
material - the material
textureType - the type of the texture
Returns:
true if the texture exists in the material and false otherwise

getMaterials

public MaterialContext[] getMaterials(Structure structureWithMaterials,
                                      BlenderContext blenderContext)
                               throws BlenderFileException
This method returns the table of materials connected to the specified structure. The given structure can be of any type (ie. mesh or curve) but needs to have 'mat' field/

Parameters:
structureWithMaterials - the structure containing the mesh data
blenderContext - the blender context
Returns:
a list of vertices colors, each color belongs to a single vertex
Throws:
BlenderFileException - this exception is thrown when the blend file structure is somehow invalid or corrupted

rgbToHsv

public void rgbToHsv(float r,
                     float g,
                     float b,
                     float[] hsv)
This method converts rgb values to hsv values.

Parameters:
r - red value of the color
g - green value of the color
b - blue value of the color
hsv - hsv values of a color (this table contains the result of the transformation)

hsvToRgb

public void hsvToRgb(float h,
                     float s,
                     float v,
                     float[] rgb)
This method converts rgb values to hsv values.

Parameters:
h - hue
s - saturation
v - value
rgb - rgb result vector (should have 3 elements)

shouldBeLoaded

public boolean shouldBeLoaded(Structure structure,
                              BlenderContext blenderContext)
Description copied from class: AbstractBlenderHelper
This method analyzes the given structure and the data contained within blender context and decides if the feature should be loaded.

Specified by:
shouldBeLoaded in class AbstractBlenderHelper
Parameters:
structure - structure to be analyzed
blenderContext - the blender context
Returns:
true if the feature should be loaded and false otherwise