我在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
发布于 2012-09-13 19:28:45
如果表面上的一些区域真的是黑色的(0x000000),我会猜测一些法线实际上是指向模型内部而不是外部。
您可以检查所有三角形的顶点v1,v2,v3是否按右侧顺序定义(只需测试det(v1,v2,v3) >0),并相应地对点进行重新排序。或者,检测“相反”法线并将其乘以-1
https://stackoverflow.com/questions/10777095
复制相似问题