/// <summary> /// Emit a vertex to OBJ. The first vertex listed /// in the file has index 1, and subsequent ones /// are numbered sequentially. /// </summary> static void EmitVertex(StreamWriter s, PointInt p) { s.WriteLine(_mtl_vertex, ObjExportUtil.RealString(p.X), ObjExportUtil.RealString(p.Y), ObjExportUtil.RealString(p.Z)); }
void ExportElements( IJtFaceEmitter emitter, FilteredElementCollector collector, Options opt) { int nElements = 0; int nSolids = 0; // 导出所有构建 foreach (Element e in collector) { nElements += ExportElement(emitter, e, opt, ref nSolids); } int nFaces = emitter.GetFaceCount(); int nTriangles = emitter.GetTriangleCount(); int nVertices = emitter.GetVertexCount(); string msg = string.Format( "{0} element{1} with {2} solid{3}, " + "{4} face{5}, {6} triangle{7} and " + "{8} vertice{9} exported.", nElements, ObjExportUtil.PluralSuffix(nElements), nSolids, ObjExportUtil.PluralSuffix(nSolids), nFaces, ObjExportUtil.PluralSuffix(nFaces), nTriangles, ObjExportUtil.PluralSuffix(nTriangles), nVertices, ObjExportUtil.PluralSuffix(nVertices)); InfoMsg(msg); }
/// <summary> /// Write a new colour definition to the /// material library. /// Revit transparency lies between 0 and 100, /// where 100 is completely transparent and 0 /// opaque. In MTL, the transparency is written /// using either a 'd' or a 'Tr' statement with /// values ranging from 0.0 to 1.0, where 1.0 is /// opaque. /// </summary> static void EmitColorTransparency( StreamWriter s, int trgb) { // 透明度 int transparency; Color color = ObjExportUtil.IntToColorTransparency( trgb, out transparency); string name = ObjExportUtil.ColorTransparencyString( color, transparency); if (_more_transparent && 0 < transparency) { transparency = 100; } s.WriteLine(_mtl_newmtl_d, name, color.Red / 255.0, color.Green / 255.0, color.Blue / 255.0, (100 - transparency) / 100.0); }
/// <summary> /// Export an element, i.e. all non-empty solids /// encountered, and return the number of elements /// exported. /// If the element is a group, this method is /// called recursively on the group members. /// </summary> int ExportElement( IJtFaceEmitter emitter, Element e, Options opt, ref int nSolids) { if (e is Group group) { int n = 0; foreach (ElementId id in group.GetMemberIds()) { Element e2 = e.Document.GetElement(id); n += ExportElement(emitter, e2, opt, ref nSolids); } return(n); } string desc = ObjExportUtil.ElementDescription(e); Category cat = e.Category; if (null == cat) { Debug.Print("Element '{0}' has no category.", desc); return(0); } Material material = cat.Material; // Column category has no material, maybe all // family instances have no defualt material, // so we cannot simply skip them here: //if( null == material ) //{ // Debug.Print( "Category '{0}' of element '{1}' " // + "has no material.", cat.Name, desc ); // return 0; //} Color color = material?.Color; int transparency = (null == material) ? 0 : material.Transparency; //Debug.Assert( null != color, // "expected a valid category material colour" ); nSolids += ExportSolids(emitter, e, opt, color, transparency); return(1); }
/// <summary> /// Add a new entry for the given colour, /// if needed. Return true if the given /// colour differs from the current colour, /// and update the current colour. /// </summary> public bool AddColorTransparency(Color color, int transparency) { int trgb = ObjExportUtil.ColorTransparencyToInt(color, transparency); if (!ContainsKey(trgb)) { this[trgb] = Count; } bool rc = !_current.Equals(trgb); _current = trgb; return(rc); }
/// <summary> /// Emit a Revit geometry Face object and /// return the number of resulting triangles. /// </summary> public int EmitFace(Element e, Face face, Color color, int transparency) { ++_faceCount; var objModel = new ObjModel() { UniqueId = e.UniqueId, Faces = new List <VFace>(), vt = new List <object>() }; _objModels.Add(objModel); // 保存每个实体的材质颜色 if (_add_color && _color_transparency_lookup.AddColorTransparency(color, transparency)) { // 设置材质颜色id string name = ObjExportUtil.ColorTransparencyString(color, transparency); objModel.Mtl = name; } Mesh mesh = face.Triangulate(0 / 15.0); //Mesh mesh = face.Triangulate(); #region 保存 Vertex 及 Triangle 数据 int numTriangles = mesh.NumTriangles; for (int i = 0; i < numTriangles; ++i) { ++_triangleCount; MeshTriangle meshTriangle = mesh.get_Triangle(i); StoreTriangle(meshTriangle, objModel); } #endregion return(numTriangles); }
public ColorTransparencyLookup() { _current = ObjExportUtil.ColorTransparencyToInt( Command.DefaultColor, 0); }