2011-04-13 59 views
0

我是相當新的java3D和在stackoverflow。我的問題是我嘗試添加一個BufferedImage紋理到一個矩形,並沒有出現。我將BufferedImage保存到一個文件中,所以我確信它不是空的。 「bi」是BufferedImage。看起來我能找到關於java3D的東西已經過時了。評論是關於它上面的命令,而不是下面的。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 

回答

0

好的,我找到了解決方案。看起來紋理加載器.ALLOW_NON_POWER_OF_TWO使紋理加載器加載沒有2尺寸大小的紋理,但java3d仍然不會在多邊形上拉伸它。也可能是某個地方的標誌,因爲加載你無法使用的紋理似乎是毫無意義的。