1

私は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
4

1 に答える 1

0

わかりました、私は解決策を見つけました。TextureLoader.ALLOW_NON_POWER_OF_TWOは、テクスチャローダーに2サイズの累乗のないテクスチャをロードさせるようですが、java3dはそれをポリゴン上でストレッチしません。使用できないようなテクスチャをロードするのは非常に無意味であるように思われるので、そのためのフラグになる可能性もあります。

于 2011-04-14T06:36:44.887 に答える