我对QuadArray 3D上的纹理2D有疑问。
当我在quad数组上应用纹理时,结果不是我所期望的: 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 :(得分: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)});