我在 windows 中的 eclipse Indigo 下使用 Java3d。在最终修改 StlLoader 示例和 ObjLoad 类以加载我的 STL 文件后,我得到如下所示的结果(我认为从其他问题来看这些绝对是错误的矢量法线)。有人知道我为什么会遇到这个问题吗?我正在使用 SolidWorks 将 STL 保存为 ASCII 文件,并使用修改代码来加载 java3d.org 上给出的 STL 文件。虽然我只更改了一些外观属性并修复了损坏的导入等。我已经确认放入下面的“normList”的刻面法线与文件中的法线完全匹配。
结果示例:
来自http://www.java3d.org的 StlFile.java 片段:
private SceneBase makeScene()
{
// Create Scene to pass back
SceneBase scene = new SceneBase();
BranchGroup group = new BranchGroup();
scene.setSceneGroup(group);
// Store the scene info on a GeometryInfo
GeometryInfo gi = new GeometryInfo(GeometryInfo.TRIANGLE_STRIP_ARRAY);
// Convert ArrayLists to arrays: only needed if file was not binary
if(this.Ascii)
{
coordArray = objectToPoint3Array(coordList);
normArray = objectToVectorArray(normList);
}
gi.setCoordinates(coordArray);
gi.setNormals(normArray);
gi.setStripCounts(stripCounts);
// Setting the Material Appearance
Appearance app = new Appearance();
// Coloring Attributes
ColoringAttributes catt = new ColoringAttributes();
catt.setShadeModel( ColoringAttributes.NICEST );
app.setColoringAttributes(catt);
Material mat = new Material(new Color3f(0.6f, 0.6f, 0.6f), // ambient
new Color3f(0, 0, 0), // emissive
new Color3f(0.6f, 0.6f, 0.6f), // diffuse
new Color3f(0.6f, 0.6f, 0.6f), // specular
10); // shininess
app.setMaterial(mat);
// Put geometry into Shape3d
Shape3D shape = new Shape3D(gi.getGeometryArray(), app);
group.addChild(shape);
scene.addNamedObject(objectName, shape);
return scene;
} // end of makeScene