2012-05-27 34 views
0

我正在使用Eclipse中的Eclipse3下的Java3d。在最终修改StlLoader示例和ObjLoad类以获得我的STL文件加载后,我得到的结果如下(我认为从其他问题来看,这些绝对是不好的向量法线)。有人知道我为什么会遇到这个问题吗?我正在使用SolidWorks将STL保存为ASCII文件,并使用修改的代码来加载java3d.org上给出的STL文件。虽然我只改变了一些外观属性并修复了损坏的导入等。我已经确认下面的“normList”方面的法线与文件中的法线相匹配。结果的Java3d - 使用GeometryInfo的差法线

例子:

enter image description here

StlFile.java的片段从http://www.java3d.org

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 
+0

如果您尝试像立方体或球体那样简单,看起来是否正确?试图猜测这是模型文件还是代码的问题。 – Tim

+0

球体的结果几乎相同。文件中的法线看起来有些合理。有没有人知道一种方法轻松地按颜色或箭头/线条绘制法线? Sphere pic [here](http://i.imgur.com/j02Ng.png) –

+0

有没有人发现过关于此主题的任何内容? –

回答

0

如果表面上的一些区域是真正的黑色(0x000000处),我猜一些法线实际上是向内指向模型而不是向外。

您可以检查所有三角形的顶点v1,v2,v3是否按右手顺序定义(仅测试det(v1,v2,v3)> 0)并相应地重新排序点。或者,检测“相反”的法线并将它们乘以-1