2016-03-03 78 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)});