我是Java3D的新手,并尝试显示一个三角形,但它没有显示,框架是完全黑色的。 如果我添加
bg.addChild(new ColorCube(0.3));
它在中间显示一个红色方块(因此通常显示形状应该有效,不应该吗?)
我真的不知道问题是关于三角形本身的构造还是视图的其他部分,例如三角形不是焦点,太小,不亮等。来自TriangleArray的多边形是否必须由光源点亮,或者它们是否显示为无光泽物体?
以下是代码:
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.geometry.GeometryInfo;
import com.sun.j3d.utils.geometry.NormalGenerator;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import javax.swing.JFrame;
import javax.media.j3d.*;
import javax.vecmath.Color3f;
import javax.vecmath.Color4f;
import javax.vecmath.Point3d;
import javax.vecmath.Point3f;
import javax.vecmath.Vector3f;
public class Simulator extends Frame {
Point3f[] testTrianglePoints = {
new Point3f(0.0f ,0.0f, 1.0f),
new Point3f(0.0f, 0.0f, 1.2f),
new Point3f(0.2f, 0.2f, 1.2f)};
Simulator() {
System.out.println("Simulator window initiated");
}
public void run() {
SimpleUniverse u = new SimpleUniverse();
BranchGroup bg = new BranchGroup();
//bg.addChild(new ColorCube(0.3));
TriangleArray t_geo = new TriangleArray(9, TriangleArray.COORDINATES);
t_geo.setCoordinates(0,testTrianglePoints);
GeometryArray t_geoArray = (new GeometryInfo(t_geo)).getGeometryArray();
Shape3D t_shape = new Shape3D(t_geoArray,new Appearance());
bg.addChild(t_shape);
u.addBranchGraph(bg);
u.getViewingPlatform().setNominalViewingTransform();
}
}
`