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