2016-03-03 64 views
0

我有一個關於2D紋理上QuadArray 3D問題。的Java 3D紋理變形

當我申請的四陣列上的紋理結果不是我所期望的: Texture on quadarray I have

由於四是平面的我期待有一個更光滑的質地變形: Texture I expect

這裏是我的代碼使用:

public class Test3D extends JPanel { 
SimpleUniverse simpleU; 
static boolean application = false; 

public BranchGroup createSceneGraph() { 
    BranchGroup objRoot = new BranchGroup(); 
    Appearance polygon1Appearance = new Appearance(); 

    GeometryInfo polygon1 = new GeometryInfo(GeometryInfo.QUAD_ARRAY); 

    polygon1.setTextureCoordinateParams(1, 2); 

    polygon1.setCoordinates(new Point3f[]{new Point3f(0f, 0f, 0f), new Point3f(2f, 0f, 0f), new Point3f(3f, 3f, 0f), new Point3f(-3f, 3f, 0f)}); 

    polygon1.setTextureCoordinates(0, new TexCoord4f[]{new TexCoord2f(0.0f, 0.0f)// 
      , new TexCoord2f(1.0f, 0.0f) // 
      , new TexCoord2f(1.0f, 1.0f) // 
      , new TexCoord2f(0.0f, 1.0f)}); 

    NormalGenerator normalGenerator = new NormalGenerator(); 
    normalGenerator.generateNormals(polygon1); 

    Texture texImage = new TextureLoader("texture.png", this).getTexture(); 

    polygon1Appearance.setTexture(texImage); 
    objRoot.addChild(new Shape3D(polygon1.getGeometryArray(), polygon1Appearance)); 
    return objRoot; 
} 

public Test3D() { 
    init(); 
} 



public void init() { 
    setLayout(new BorderLayout()); 

    Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); 
    add("Center", c); 
    BranchGroup scene = createSceneGraph(); 
    simpleU = new SimpleUniverse(c); 
    TransformGroup tg = simpleU.getViewingPlatform().getViewPlatformTransform(); 
    Transform3D t3d = new Transform3D(); 
    t3d.setTranslation(new Vector3f(0f, 0f, 10f)); 
    tg.setTransform(t3d); 
    scene.compile(); 
    simpleU.addBranchGraph(scene); 
} 



public static void main(final String[] args) { 
    application = true; 
    JFrame frame = new JFrame(); 
    frame.setSize(500, 500); 
    frame.add(new Test3D()); 
    frame.setVisible(true); 
}} 

有沒有人有任何解決方案來解決這個問題?

+0

您好,形狀爲平面梯形,沒有任何三角形。通過改變位置,我幾乎相同的結果,如果Java3D的分裂飛人成兩個三角形,並把紋理就可以了... – ivan

+0

*彷彿Java3D的分裂飛人成兩個三角形,並把紋理上* [擾流:如果不是通過Java,然後通過你的顯卡]你必須處理這個事實。 – BeyelerStudios

+0

這個問題在這裏解釋:[http://www.xyzw.us/~cass/qcoord/](http://www.xyzw.us/~cass/qcoord/) – derhass

回答

0

不幸的是,在http://www.xyzw.us/~cass/qcoord/作品梯形幾何形狀的解決方案,但對於非特異性四邊形這個解決方案是行不通的。

例:

polygon1.setCoordinates(new Point3f[]{new Point3f(0f, 0f, 0f), new Point3f(2f, -1f, 0f), new Point3f(3f, 3f, 0f), new Point3f(-4f, 3f, 0f)});