1

我在 java3D 和 stackoverflow 上都是新手。我的问题是我尝试将 BufferedImage 纹理添加到矩形,但它没有出现。我将 BufferedImage 保存到一个文件中,所以我确定它不是空的。“bi”是缓冲图像。我能找到的关于 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
4

1 回答 1

0

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

于 2011-04-14T06:36:44.887 回答