@ -14,32 +14,32 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper;
import com.jme3.texture.Texture.Type ;
import com.jme3.texture.Texture.Type ;
public final class MaterialContext {
public final class MaterialContext {
private static final Logger LOGGER = Logger . getLogger ( MaterialContext . class . getName ( ) ) ;
private static final Logger LOGGER = Logger . getLogger ( MaterialContext . class . getName ( ) ) ;
/*package*/ final String name ;
/* package */ final String name ;
/*package*/ final List < Structure > mTexs ;
/* package */ final List < Structure > mTexs ;
/*package*/ final List < Structure > textures ;
/* package */ final List < Structure > textures ;
/*package*/ final int texturesCount ;
/* package */ final int texturesCount ;
/*package*/ final Type textureType ;
/* package */ final Type textureType ;
/*package*/ final boolean shadeless ;
/* package */ final boolean shadeless ;
/*package*/ final boolean vertexColor ;
/* package */ final boolean vertexColor ;
/*package*/ final boolean transparent ;
/* package */ final boolean transparent ;
/*package*/ final boolean vtangent ;
/* package */ final boolean vtangent ;
/*package*/ int uvCoordinatesType = - 1 ;
/* package */ int uvCoordinatesType = - 1 ;
/*package*/ int projectionType ;
/* package */ int projectionType ;
@SuppressWarnings ( "unchecked" )
@SuppressWarnings ( "unchecked" )
/*package*/ MaterialContext ( Structure structure , DataRepository dataRepository ) throws BlenderFileException {
/* package */ MaterialContext ( Structure structure , DataRepository dataRepository ) throws BlenderFileException {
name = structure . getName ( ) ;
name = structure . getName ( ) ;
int mode = ( ( Number ) structure . getFieldValue ( "mode" ) ) . intValue ( ) ;
int mode = ( ( Number ) structure . getFieldValue ( "mode" ) ) . intValue ( ) ;
shadeless = ( mode & 0x4 ) ! = 0 ;
shadeless = ( mode & 0x4 ) ! = 0 ;
vertexColor = ( mode & 0x80 ) ! = 0 ;
vertexColor = ( mode & 0x80 ) ! = 0 ;
transparent = ( mode & 0x10000 ) ! = 0 ;
transparent = ( mode & 0x10000 ) ! = 0 ;
vtangent = ( mode & 0x4000000 ) ! = 0 ; // NOTE: Requires tangents
vtangent = ( mode & 0x4000000 ) ! = 0 ; // NOTE: Requires tangents
mTexs = new ArrayList < Structure > ( ) ;
mTexs = new ArrayList < Structure > ( ) ;
textures = new ArrayList < Structure > ( ) ;
textures = new ArrayList < Structure > ( ) ;
DynamicArray < Pointer > mtexsArray = ( DynamicArray < Pointer > ) structure . getFieldValue ( "mtex" ) ;
DynamicArray < Pointer > mtexsArray = ( DynamicArray < Pointer > ) structure . getFieldValue ( "mtex" ) ;
@ -49,41 +49,41 @@ public final class MaterialContext {
Pointer p = mtexsArray . get ( i ) ;
Pointer p = mtexsArray . get ( i ) ;
if ( p . isNotNull ( ) & & ( separatedTextures & 1 < < i ) = = 0 ) {
if ( p . isNotNull ( ) & & ( separatedTextures & 1 < < i ) = = 0 ) {
Structure mtex = p . fetchData ( dataRepository . getInputStream ( ) ) . get ( 0 ) ;
Structure mtex = p . fetchData ( dataRepository . getInputStream ( ) ) . get ( 0 ) ;
//the first texture determines the texture coordinates type
// the first texture determines the texture coordinates type
if ( uvCoordinatesType = = - 1 ) {
if ( uvCoordinatesType = = - 1 ) {
uvCoordinatesType = ( ( Number ) mtex . getFieldValue ( "texco" ) ) . intValue ( ) ;
uvCoordinatesType = ( ( Number ) mtex . getFieldValue ( "texco" ) ) . intValue ( ) ;
projectionType = ( ( Number ) mtex . getFieldValue ( "mapping" ) ) . intValue ( ) ;
projectionType = ( ( Number ) mtex . getFieldValue ( "mapping" ) ) . intValue ( ) ;
} else if ( uvCoordinatesType ! = ( ( Number ) mtex . getFieldValue ( "texco" ) ) . intValue ( ) ) {
} else if ( uvCoordinatesType ! = ( ( Number ) mtex . getFieldValue ( "texco" ) ) . intValue ( ) ) {
LOGGER . log ( Level . WARNING , "The texture with index: {0} has different UV coordinates type than the first texture! This texture will NOT be loaded!" , i + 1 ) ;
LOGGER . log ( Level . WARNING , "The texture with index: {0} has different UV coordinates type than the first texture! This texture will NOT be loaded!" , i + 1 ) ;
continue ;
continue ;
}
}
Pointer pTex = ( Pointer ) mtex . getFieldValue ( "tex" ) ;
Pointer pTex = ( Pointer ) mtex . getFieldValue ( "tex" ) ;
if ( pTex . isNotNull ( ) ) {
if ( pTex . isNotNull ( ) ) {
Structure tex = pTex . fetchData ( dataRepository . getInputStream ( ) ) . get ( 0 ) ;
Structure tex = pTex . fetchData ( dataRepository . getInputStream ( ) ) . get ( 0 ) ;
int type = ( ( Number ) tex . getFieldValue ( "type" ) ) . intValue ( ) ;
int type = ( ( Number ) tex . getFieldValue ( "type" ) ) . intValue ( ) ;
Type textureType = this . getType ( type ) ;
Type textureType = this . getType ( type ) ;
if ( textureType ! = null ) {
if ( textureType ! = null ) {
if ( firstTextureType = = null ) {
if ( firstTextureType = = null ) {
firstTextureType = textureType ;
firstTextureType = textureType ;
mTexs . add ( mtex ) ;
mTexs . add ( mtex ) ;
textures . add ( tex ) ;
textures . add ( tex ) ;
} else if ( firstTextureType = = textureType ) {
} else if ( firstTextureType = = textureType ) {
mTexs . add ( mtex ) ;
mTexs . add ( mtex ) ;
textures . add ( tex ) ;
textures . add ( tex ) ;
} else {
} else {
LOGGER . log ( Level . WARNING , "The texture with index: {0} is of different dimension than the first one! This texture will NOT be loaded!" , i + 1 ) ;
LOGGER . log ( Level . WARNING , "The texture with index: {0} is of different dimension than the first one! This texture will NOT be loaded!" , i + 1 ) ;
}
}
}
}
}
}
}
}
}
}
this . texturesCount = mTexs . size ( ) ;
this . texturesCount = mTexs . size ( ) ;
this . textureType = firstTextureType ;
this . textureType = firstTextureType ;
}
}
/ * *
/ * *
* This method returns the current material ' s texture UV coordinates type .
* This method returns the current material ' s texture UV coordinates type .
* @return uv coordinates type
* @return uv coordinates type
@ -91,7 +91,7 @@ public final class MaterialContext {
public int getUvCoordinatesType ( ) {
public int getUvCoordinatesType ( ) {
return uvCoordinatesType ;
return uvCoordinatesType ;
}
}
/ * *
/ * *
* This method returns the proper projection type for the material ' s texture .
* This method returns the proper projection type for the material ' s texture .
* This applies only to 2D textures .
* This applies only to 2D textures .
@ -108,7 +108,7 @@ public final class MaterialContext {
public int getTextureDimension ( ) {
public int getTextureDimension ( ) {
return this . textureType = = Type . TwoDimensional ? 2 : 3 ;
return this . textureType = = Type . TwoDimensional ? 2 : 3 ;
}
}
/ * *
/ * *
* This method returns the amount of textures applied for the current
* This method returns the amount of textures applied for the current
* material .
* material .
@ -118,10 +118,26 @@ public final class MaterialContext {
public int getTexturesCount ( ) {
public int getTexturesCount ( ) {
return textures = = null ? 0 : textures . size ( ) ;
return textures = = null ? 0 : textures . size ( ) ;
}
}
/ * *
* This method returns the projection array that indicates where the current coordinate factor X , Y or Z ( represented
* by the index in the array ) will be used where ( indicated by the value in the array ) .
* For example the configuration : [ 1 , 2 , 3 ] means that X - coordinate will be used as X , Y as Y and Z as Z .
* The configuration [ 2 , 1 , 0 ] means that Z will be used instead of X coordinate , Y will be used as Y and
* Z will not be used at all ( 0 will be in its place ) .
* @param textureIndex
* the index of the texture
* @return texture projection array
* /
public int [ ] getProjection ( int textureIndex ) {
Structure mtex = mTexs . get ( textureIndex ) ;
return new int [ ] { ( ( Number ) mtex . getFieldValue ( "projx" ) ) . intValue ( ) , ( ( Number ) mtex . getFieldValue ( "projy" ) ) . intValue ( ) , ( ( Number ) mtex . getFieldValue ( "projz" ) ) . intValue ( ) } ;
}
/ * *
/ * *
* This method determines the type of the texture .
* This method determines the type of the texture .
* @param texType texture type ( from blender )
* @param texType
* texture type ( from blender )
* @return texture type ( used by jme )
* @return texture type ( used by jme )
* /
* /
private Type getType ( int texType ) {
private Type getType ( int texType ) {
@ -142,7 +158,7 @@ public final class MaterialContext {
case TextureHelper . TEX_NONE : // No texture, do nothing
case TextureHelper . TEX_NONE : // No texture, do nothing
return null ;
return null ;
case TextureHelper . TEX_POINTDENSITY :
case TextureHelper . TEX_POINTDENSITY :
case TextureHelper . TEX_VOXELDATA :
case TextureHelper . TEX_VOXELDATA :
case TextureHelper . TEX_PLUGIN :
case TextureHelper . TEX_PLUGIN :
case TextureHelper . TEX_ENVMAP :
case TextureHelper . TEX_ENVMAP :
LOGGER . log ( Level . WARNING , "Texture type NOT supported: {0}" , texType ) ;
LOGGER . log ( Level . WARNING , "Texture type NOT supported: {0}" , texType ) ;