1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
texture = null;
if (texturesDictionary.contains(mat.textureFileName)) {
texture = (Texture2D) texturesDictionary.get(mat.textureFileName);
} else {
if (mat.textureFileName!= null) {
if (mat.textureFileName!= "") {
System.out.println("debug :" + "textures/" + mat.textureFileName);
TextureLoader texLoader = new TextureLoader(getClass().getResource("textures/"+ mat.textureFileName), TextureLoader.GENERATE_MIPMAP, null);
texture = (Texture2D) texLoader.getTexture();
//System.out.println("debug : Texture format : " + texture.getFormat() + " " + Texture2D.RGBA);
texture.setMipMapMode(Texture.MULTI_LEVEL_MIPMAP);
texture.setAnisotropicFilterMode(Texture.ANISOTROPIC_SINGLE_VALUE);
texturesDictionary.put(mat.textureFileName, texture);
}
}
}
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
texAttr.setTextureBlendColor(new Color4f(0.0f, 0.0f, 0.0f, 1.0f));
texAttr.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
texAttr.setCombineAlphaSource(0,TextureAttributes.COMBINE_TEXTURE_COLOR);
texAttr.setCombineAlphaFunction(0,TextureAttributes.COMBINE_ONE_MINUS_SRC_ALPHA);
/*****************************/
ColoringAttributes colAttrib = new ColoringAttributes();
colAttrib.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_READ);
colAttrib.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE);
colAttrib.setShadeModel(ColoringAttributes.SHADE_GOURAUD);
appear.setColoringAttributes(colAttrib);
Material javaMat = new Material( new Color3f(mat.diffusionR,mat.diffusionG, mat.diffusionB),
new Color3f(mat.emissionR,mat.emissionG, mat.emissionB),
new Color3f(mat.diffusionR,mat.diffusionG, mat.diffusionB),
new Color3f(mat.specularityR,mat.specularityG, mat.specularityB),
mat.specularity
);
appear.setMaterial(javaMat);
// attributs des polygones : leurs deux faces devront etres affichables
PolygonAttributes polyAttrib = new PolygonAttributes();
polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
appear.setPolygonAttributes(polyAttrib);
/*****************************/
if (texture!= null) {
appear.setTexture(texture);
appear.setTextureAttributes(texAttr);
}
shape.setAppearance(appear);
object3d.addChild(shape); |
Partager