/// <summary> /// Adds a face to the edge's face list if the face index is in range. (Some /// shapes, such as "plate / alloys", use $ff for their edge face value even /// though fewer than 16 faces are defined.) /// </summary> private void AddEdgeFace(VisWireframe vw, int eindex, int face, int faceCount) { if (face < faceCount) { vw.AddEdgeFace(eindex, face); } }
private IVisualizationWireframe GenerateWireframe(ReadOnlyDictionary <string, object> parms) { int offset = Util.GetFromObjDict(parms, P_OFFSET, 0); if (offset < 0 || offset >= mFileData.Length) { // should be caught by editor mAppRef.ReportError("Invalid parameter"); return(null); } VisWireframe vw = new VisWireframe(); const sbyte END_MARKER = -128; // 0x80 try { while (true) { int vx = (sbyte)mFileData[offset++]; if (vx == END_MARKER) { break; } int vy = (sbyte)mFileData[offset++]; int vz = (sbyte)mFileData[offset++]; vw.AddVertex(vx, vy, vz); } while (true) { int v0 = (sbyte)mFileData[offset++]; if (v0 == END_MARKER) { break; } int v1 = mFileData[offset++]; int f0 = mFileData[offset++]; int f1 = mFileData[offset++]; int edge = vw.AddEdge(v0, v1); vw.AddEdgeFace(edge, f0); if (f1 != f0) { vw.AddEdgeFace(edge, f1); } } while (true) { int nx = (sbyte)mFileData[offset++]; if (nx == END_MARKER) { break; } int ny = (sbyte)mFileData[offset++]; int nz = (sbyte)mFileData[offset++]; vw.AddFaceNormal(nx, ny, nz); } } catch (IndexOutOfRangeException) { // assume it was our file data access that caused the failure mAppRef.ReportError("Ran off end of file"); return(null); } string msg; if (!vw.Validate(out msg)) { mAppRef.ReportError("Data error: " + msg); return(null); } return(vw); }