BufferedImage纹理没有出现在java3D中

| 我在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
    
已邀请:
好的,我已经找到了解决方案。看来TextureLoader.ALLOW_NON_POWER_OF_TWO使纹理加载器加载没有2大小幂的纹理,但是java3d仍然不会在多边形上拉伸它。可能也为此设置了一个标志,因为加载无法使用的纹理似乎毫无意义。     

要回复问题请先登录注册