//累加模型体积 private int AddVolumeProperty(VolumeProperties vp, Entity ent, out bool blockReferenceNotScaled, bool all = false, bool isParentSelected = false) { int count = 0; blockReferenceNotScaled = true; if (all || ent.Selected || isParentSelected) { if (ent is IFace) { IFace itfFace = (IFace)ent; Mesh[] meshes = itfFace.GetPolygonMeshes(); foreach (Mesh mesh in meshes) { vp.Add(mesh.Vertices, mesh.Triangles); } count++; } else if (ent is BlockReference) { var br = (BlockReference)ent; if (br.GetScaleFactorX() != 1 && br.GetScaleFactorY() != 1 && br.GetScaleFactorZ() != 1) { blockReferenceNotScaled = false; return(count); } foreach (var e in br.GetEntities(model.Blocks)) { count += AddVolumeProperty(vp, e, out blockReferenceNotScaled, true); if (!blockReferenceNotScaled) { return(count); } } } } return(count); }
//累加模型面积 private int AddAreaProperty(AreaProperties ap, Entity ent, out bool blockReferenceNotScaled, bool isParentSelected = false, bool all = false) { int count = 0; blockReferenceNotScaled = true; if (all || ent.Selected || isParentSelected) { if (ent is IFace) { IFace itfFace = (IFace)ent; Mesh[] meshes = itfFace.GetPolygonMeshes(); foreach (Mesh mesh in meshes) { ap.Add(mesh.Vertices, mesh.Triangles); } count++; } else if (ent is BlockReference) { var br = (BlockReference)ent; if (br.GetScaleFactorX() != 1 && br.GetScaleFactorY() != 1 && br.GetScaleFactorZ() != 1) { blockReferenceNotScaled = false; return(count); } foreach (var e in br.GetEntities(model.Blocks)) { count += AddAreaProperty(ap, e, out blockReferenceNotScaled, true); if (!blockReferenceNotScaled) { return(count); } } } else { ICurve itfCurve = (ICurve)ent; if (itfCurve.IsClosed) { ap.Add(ent.Vertices); } count++; } } else if (ent is Brep) { Brep brep = (Brep)ent; for (int j = 0; j < brep.Faces.Length; j++) { Brep.Face sf = brep.Faces[j]; Mesh[] faceTessellation = sf.Tessellation; if (brep.GetFaceSelection(j)) { foreach (Mesh m in faceTessellation) { ap.Add(m.Vertices, m.Triangles); } count++; } } } return(count); }