我使用Helix3d工具包导入模型。接下来,我对3D模型执行命中测试。然后我从rayMeshResult.Meshit获取MeshGeometry3D信息。最后,我从MeshGeometry3D获取顶点位置信息和triangleIndices。现在我从LinesVisual3D克隆点,然后将triangleIndices / vertex信息提供给克隆。最后,我将克隆的点数据复制到LinesVisual3D.Points中,并将这些行添加到我的视口中。
从链接的图片中可以看出,并非绘制了立方体的所有边缘,但所有点都在那里。
http://www.freeimagehosting.net/fhws5
GeometryModel3D hitgeo = rayMeshResult.ModelHit as GeometryModel3D;
MeshGeometry3D newGeom = rayMeshResult.MeshHit as MeshGeometry3D;
Point3DCollection srtpnt = modelLines.Points.Clone();
for (int i = 0; i < newGeom.TriangleIndices.Count; i ++)
{
srtpnt.Add(newGeom.Positions[newGeom.TriangleIndices[i]]);
textBlock4.Text += newGeom.Positions[newGeom.TriangleIndices[i]].ToString() + "\n";
}
modelLines.Points = srtpnt;
modelPoints.Points = srtpnt;
modelPoints.Color = Colors.Red;
modelPoints.Size = 15;
modelLines.Thickness = 6;
modelLines.Color = Colors.Blue;
MainViewport.ClearChildren();
MainViewport.Children.Add(modelLines);
MainViewport.Children.Add(modelPoints);
UpdateResultInfo(rayMeshResult);