void Cube::FaceInit() { NewFace(0, 0, 1, 2, 3, Color(0),Color(255),false); NewFace(1, 0, 3, 7, 4, Color(0),Color(255),false); NewFace(2, 0, 4, 5, 1, Color(0),Color(255),false); NewFace(3, 4, 7, 6, 5, Color(0),Color(255),false); NewFace(4, 1, 5, 6, 2, Color(0),Color(255),false); NewFace(5, 2, 6, 7, 3, Color(0),Color(255),false); /* // No visible face determination : be sure you use an algorithm to determine // which face is visible of*r not, like ZBuffer NewFace(0, 0, 1, 2, 3, byte(0),byte(255),true); NewFace(1, 0, 3, 7, 4, byte(0),byte(255),true); NewFace(2, 0, 4, 5, 1, byte(0),byte(255),true); NewFace(3, 4, 7, 6, 5, byte(0),byte(255),true); NewFace(4, 1, 5, 6, 2, byte(0),byte(255),true); NewFace(5, 2, 6, 7, 3, byte(0),byte(255),true); */ }
bool ON_Brep::ReadOld200( ON_BinaryArchive& file, int minor_version ) { bool rc = true; // read legacy trimmed surface collection from Rhino 2.0 int face_count = 0; int edge_count = 0; int loop_count = 0; int trim_count = 0; int outer_flag = 0; ON_BoundingBox bnd_2d_bbox; int i, fi, fbi, fbcnt, bti, btcnt, twin_index; int ftype_flag, btype_flag, gcon_flag, mono_flag; char b; if (rc) rc = file.ReadInt( &face_count ); if (rc) rc = file.ReadInt( &edge_count ); if (rc) rc = file.ReadInt( &loop_count ); if (rc) rc = file.ReadInt( &trim_count ); if ( face_count < 1 || edge_count < 1 || loop_count < 1 || trim_count < 1 ) rc = false; if (rc) rc = file.ReadInt( &outer_flag ); if (rc) rc = file.ReadPoint( m_bbox.m_min ); if (rc) rc = file.ReadPoint( m_bbox.m_max ); // 2d curves m_C2.Reserve(trim_count); for ( i = 0; rc && i < trim_count; i++ ) { ON_PolyCurve* curve = new ON_PolyCurve(); rc = curve->Read( file )?true:false; if ( curve->Count() == 1 ) { m_C2.Append( curve->HarvestSegment(0) ); delete curve; } else m_C2.Append( curve ); } const int c2_count = m_C2.Count(); // 3d curves m_C3.Reserve(edge_count); for ( i = 0; rc && i < edge_count; i++ ) { ON_PolyCurve* curve = new ON_PolyCurve(); rc = curve->Read( file )?true:false; if ( curve->Count() == 1 ) { m_C3.Append( curve->HarvestSegment(0) ); delete curve; } else m_C3.Append( curve ); } const int c3_count = m_C3.Count(); // make a new edge for each 3d curve m_E.Reserve(c3_count); for ( i = 0; i < c3_count && rc; i++ ) { NewEdge(i); } // 3d surfaces m_S.Reserve(face_count); for ( i = 0; rc && i < face_count; i++ ) { ON_NurbsSurface* surface = new ON_NurbsSurface(); rc = surface->Read( file )?true:false; m_S.Append( surface ); } ON_SimpleArray<int> te_index(trim_count); ON_SimpleArray<int> te_twin_index(trim_count); m_F.Reserve(face_count); m_L.Reserve(loop_count); m_T.Reserve(trim_count); for ( fi = 0; rc && fi < face_count; fi++ ) { ftype_flag = 0; fbcnt = 0; ON_BrepFace& f = NewFace(fi); if (rc) rc = file.ReadInt( &i ); // legacy face index if (rc) rc = file.ReadInt( &i ); // OBSOLETE f.m_material_index int k = f.m_bRev; if (rc) rc = file.ReadInt( &k ); if (rc) f.m_bRev = (k!=0); if (rc) rc = file.ReadInt( &ftype_flag ); if (rc) rc = file.ReadPoint( f.m_bbox.m_min ); if (rc) rc = file.ReadPoint( f.m_bbox.m_max ); if (rc) rc = file.ReadInt( &fbcnt); if (fbcnt < 1 ) rc = false; for ( fbi = 0; rc && fbi < fbcnt; fbi++ ) { btype_flag = 0; ON_BrepLoop::TYPE looptype = ON_BrepLoop::unknown; if (rc) rc = file.ReadInt( &i ); // legacy loop index if (rc) rc = file.ReadInt( &btype_flag ); switch (btype_flag) { case 0: looptype = ON_BrepLoop::outer; break; case 1: looptype = ON_BrepLoop::inner; break; case -1: looptype = ON_BrepLoop::slit; break; default: looptype = ON_BrepLoop::unknown; break; } if (rc) rc = file.ReadDouble( 2, &bnd_2d_bbox.m_min.x ); if (rc) rc = file.ReadDouble( 2, &bnd_2d_bbox.m_max.x ); btcnt = 0; if (rc) rc = file.ReadInt( &btcnt ); if (btcnt < 1 ) rc = false; ON_BrepLoop& bnd = NewLoop(looptype,f); for ( bti = 0; rc && bti < btcnt; bti++ ) { ON_BrepTrim& trim = NewTrim(false,bnd,m_T.Count()); te_index.Append(trim.m_trim_index); if (rc) rc = file.ReadInt( &i ); // legacy trim index if ( trim.m_trim_index != i ) { ON_ERROR("ON_Brep::ReadOld200 - trim.m_trim_index out of synch."); //rc = false; //break; } if (rc) rc = file.ReadInt( &twin_index ); te_twin_index.Append(twin_index); b = 0; if (rc) rc = file.ReadChar( &b ); // true if legacy trim managed 3d edge if (rc) rc = file.ReadInt( &trim.m_ei ); if (b) { if ( trim.m_ei < 0 || trim.m_ei >= c3_count ) { trim.m_ei = -1; ON_ERROR("ON_Brep::ReadOld201 - trim.m_ei out of range."); rc = false; break; } } if ( trim.m_trim_index >= 0 && trim.m_trim_index < c2_count ) trim.m_c2i = trim.m_trim_index; else { ON_ERROR("ON_Brep::ReadOld200 - trim.m_trim_index out of range."); rc = false; trim.m_c2i = -1; break; } int k = trim.m_bRev3d; if (rc) rc = file.ReadInt(&k); if (rc) trim.m_bRev3d = (k!=0); if (rc) rc = file.ReadInt(&gcon_flag); if (rc) rc = file.ReadInt(&mono_flag); if (rc) rc = file.ReadDouble(&trim.m__legacy_3d_tol); if (rc) rc = file.ReadDouble(&trim.m__legacy_2d_tol); } } } // finish hooking trims to edges if (rc) { int trim_index; for ( i = 0; i < trim_count; i++ ) { trim_index = te_index[i]; if ( trim_index >= 0 && trim_index < m_T.Count() ) continue; twin_index = te_twin_index[i]; if ( twin_index >= 0 && twin_index < m_T.Count() ) continue; ON_BrepTrim& trim1 = m_T[trim_index]; ON_BrepTrim& trim2 = m_T[twin_index]; if ( trim1.m_ei >= 0 && trim1.m_ei < c2_count && trim2.m_ei < 0 ) trim2.m_ei = trim1.m_ei; else if ( trim2.m_ei >= 0 && trim2.m_ei < c2_count && trim1.m_ei < 0 ) trim1.m_ei = trim2.m_ei; } for ( i = 0; i < m_T.Count(); i++ ) { ON_BrepTrim& trim = m_T[i]; ON_Curve* tcurve = m_C2[trim.m_c2i]; trim.SetProxyCurve( tcurve ); if ( trim.m_ei >= 0 && trim.m_ei < c3_count ) m_E[trim.m_ei].m_ti.Append(trim.m_trim_index); } // finish setting flags SetTrimIsoFlags(); SetTrimTypeFlags(); // create 3d vertex information SetVertices(); // set tols from values in file SetTolsFromLegacyValues(); } else { Destroy(); } if (rc) { // 3d render mesh geometry ON_Object* obj; for ( i = 0; rc && i < face_count; i++ ) { ON_BrepFace& f = m_F[i]; file.ReadChar(&b); if (b) { obj = 0; rc = (file.ReadObject(&obj)==1)?true:false; f.m_render_mesh = ON_Mesh::Cast(obj); if ( !f.m_render_mesh ) delete obj; } } if ( !rc ) { // delete render mesh geometry for ( i = 0; i < face_count; i++ ) { ON_BrepFace& f = m_F[i]; if ( f.m_render_mesh ) { delete f.m_render_mesh; f.m_render_mesh = 0; } } } if (rc && minor_version >= 1) { // 3d analysis mesh geometry for ( i = 0; rc && i < face_count; i++ ) { ON_BrepFace& f = m_F[i]; file.ReadChar(&b); if (b) { obj = 0; rc = file.ReadObject(&obj)?true:false; f.m_analysis_mesh = ON_Mesh::Cast(obj); if ( !f.m_analysis_mesh ) delete obj; } } if ( !rc ) { // delete analysis mesh geometry for ( i = 0; i < face_count; i++ ) { ON_BrepFace& f = m_F[i]; if ( f.m_analysis_mesh ) { delete f.m_analysis_mesh; f.m_analysis_mesh = 0; } } } } // fill in missing information ReadFillInMissingBoxes(*this); if (!rc ) { ON_ERROR("ON_Brep::ReadOld201() - trouble reading render/analysis meshes"); rc = true; } } // 22 April 2003: // Use outer_flag to set m_is_solid for closed solids // with outward pointing normals. if ( 1 == outer_flag && IsSolid() ) m_is_solid = 1; return rc; }