2011-04-13 4 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

그래, 해결책을 찾았습니다. TextureLoader.ALLOW_NON_POWER_OF_TWO는 텍스처 로더가 2 크기의 힘을 가지지 않는 텍스처를로드하는 것처럼 보이지만 java3d는 여전히 다각형에서 텍스처를 늘리지 않을 것입니다. 사용할 수없는 텍스처를로드하는 것은 매우 무의미한 것처럼 보이기 때문에 그 어딘가에 플래그가 될 수도 있습니다.