BufferedImage纹理没有出现在java3D中

发布于 11-01 03:09 字数 1577 浏览 5 评论 0原文

我对 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

I'm quite new in java3D and on stackoverflow. My problem is I try to add a BufferedImage texture to a rectangle, and it doesnt appear. I saved the BufferedImage to a file so I'm sure it's not empty. "bi" is the BufferedImage. It seems anything I can find about java3D is quite outdated. Comments are about the commands above it, not below.

    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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅唱々樱花落2024-11-08 03:09:25

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

Ok, I've found the solution. It seems the TextureLoader.ALLOW_NON_POWER_OF_TWO makes the texture loader to load a texture that has no power of 2 size, but the java3d still wont stretch it on the polygon. Might be a flag somewhere for that too, because it seems to be very pointless to load such texture you are not able to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文