BufferedImage纹理不会出现在java3D中

时间:2011-04-13 06:28:18

标签: java java-3d

我在java3D和stackoverflow上都很新。我的问题是我尝试将BufferedImage纹理添加到矩形,但它不会出现。我将BufferedImage保存到文件中,所以我确定它不是空的。 “bi”是BufferedImage。似乎我能找到的关于java3D的任何东西都已经过时了。评论是关于它上面的命令,而不是下面的命令。

    QuadArray alap = new QuadArray(4, QuadArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);

    // [...] setting coordinates for the polygon (rectangle)

    Appearance alapAppearance = new Appearance();
    PolygonAttributes alapPa = new PolygonAttributes();

    alapAppearance.setPolygonAttributes(alapPa);

    alap.setTextureCoordinate (0, 0, new TexCoord2f(0.0f,0.0f));
    alap.setTextureCoordinate (0, 1, new TexCoord2f(1.0f,0.0f));
    alap.setTextureCoordinate (0, 2, new TexCoord2f(1.0f,1.0f));
    alap.setTextureCoordinate (0, 3, new TexCoord2f(0.0f,1.0f));
    //tryed in different order

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.REPLACE);
    TextureLoader loader = new TextureLoader(bi, TextureLoader.ALLOW_NON_POWER_OF_TWO);
    //Tryed with "RGB" flag too (as second parameter).
    Texture t1 = loader.getTexture();

t1.setBoundaryModeS(Texture.CLAMP_TO_EDGE);
t1.setBoundaryModeT(Texture.CLAMP_TO_EDGE);

    alapAppearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
    alapAppearance.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);
    //I don't think it's really needed, but can't hurt I quess.
    alapAppearance.setTextureAttributes(texAttr);
    alapAppearance.setTexture(t1);

    tfg.addChild(new Shape3D(alap, alapAppearance));
    //tfg = transformGroup

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案。似乎TextureLoader.ALLOW_NON_POWER_OF_TWO使纹理加载器加载一个没有2大小功能的纹理,但是java3d仍然不会在多边形上拉伸它。也可能是某个地方的旗帜,因为加载你无法使用的纹理似乎毫无意义。