void ON_GL( const ON_Color& rc, double alpha, GLfloat c[4] ) { c[0] = (GLfloat)rc.FractionRed(); c[1] = (GLfloat)rc.FractionGreen(); c[2] = (GLfloat)rc.FractionBlue(); c[3] = (GLfloat)alpha; }
void ON_GL( const ON_Color& rc, GLfloat c[4] ) { c[0] = (GLfloat)rc.FractionRed(); c[1] = (GLfloat)rc.FractionGreen(); c[2] = (GLfloat)rc.FractionBlue(); c[3] = (GLfloat)1.0; }
void ON_TextLog::PrintRGB( const ON_Color& color ) { if ( color == ON_UNSET_COLOR ) Print("ON_UNSET_COLOR"); else Print("%d %d %d",color.Red(),color.Green(),color.Blue()); }
ON_Color CZAnalysisVAM::FalseColor(double z) const { // Simple example of one way to change a number // into a color. double s = m_z_range.NormalizedParameterAt(z); if ( s < 0.0 ) s = 0.0; else if (s > 1.0) s = 1.0; double hue = m_hue_range.ParameterAt(s); ON_Color c; c.SetHSV( hue, 1.0, 1.0 ); return c; }
bool gfxRhino3D::loadCAD(QString filename){ int i, layer; ON_Color objCol; //Load geometry... if (filename.endsWith(".3dm")){ load3dm(filename); for (i=0;i<model.m_object_table.Count();i++){ layer=model.m_object_table[i].m_attributes.m_layer_index; if (model.m_layer_table[layer].IsVisible()){ if (ON::color_from_object == model.m_object_table[i].m_attributes.ColorSource()){ objCol=model.m_object_table[i].m_attributes.m_color; }else{ objCol=model.m_layer_table[layer].Color(); } parentObject->actor.push_back( createActor(model.m_object_table[i].m_object, objCol.FractionRed(), objCol.FractionGreen(), objCol.FractionBlue()) ); } } } for (i=0;i<parentObject->actor.size();i++) parentObject->renderer->AddActor(parentObject->actor[i]); return true; }
void CRhGLShaderProgram::SetupMaterial(const ON_Material& mat) { ON_Color dcolor = mat.Diffuse(); ON_Color scolor = mat.Specular(); ON_Color ecolor = mat.Emission(); GLfloat alpha = (GLfloat)(1.0 - mat.Transparency()); GLfloat shine = 128.0*(mat.Shine() / ON_Material::MaxShine()); GLfloat black[4] = {0.0,0.0,0.0,1.0}; GLfloat ambi[4] = { mat.Ambient().FractionRed(), mat.Ambient().FractionGreen(), mat.Ambient().FractionBlue(), mat.m_ambient.FractionAlpha() }; GLfloat diff[4] = { dcolor.FractionRed(), dcolor.FractionGreen(), dcolor.FractionBlue(), alpha }; GLfloat spec[4] = { scolor.FractionRed(), scolor.FractionGreen(), scolor.FractionBlue(), 1.0f }; GLfloat emmi[4] = { ecolor.FractionRed(), ecolor.FractionGreen(), ecolor.FractionBlue(), 1.0f }; GLfloat* pspec = shine?spec:black; if ( m_Uniforms.rglLightAmbient >= 0) { if (mat.m_ambient.Alpha() > 0) glUniform4fv( m_Uniforms.rglLightAmbient, 1, ambi ); else glUniform4fv( m_Uniforms.rglLightAmbient, 1, black ); } if ( m_Uniforms.rglDiffuse >= 0 ) glUniform4fv( m_Uniforms.rglDiffuse, 1, diff ); if ( m_Uniforms.rglSpecular >= 0 ) glUniform4fv( m_Uniforms.rglSpecular, 1, pspec ); if ( m_Uniforms.rglEmission >= 0 ) glUniform4fv( m_Uniforms.rglEmission, 1, emmi ); if ( m_Uniforms.rglShininess >= 0 ) glUniform1f( m_Uniforms.rglShininess, shine ); if ( m_Uniforms.rglUsesColors >= 0 ) glUniform1i( m_Uniforms.rglUsesColors, 0 ); if (alpha < 1.0) glEnable( GL_BLEND ); else glDisable( GL_BLEND ); }
CRhinoCommand::result CGenCylinder::RunCommand( const CRhinoCommandContext& context ) { Cscript1PlugIn& plugin = script1PlugIn(); if( !plugin.IsDlgVisible() ) { return CRhinoCommand::nothing; } /*****************************************/ /*CHECKING IF THERE IS ALREADY A CYLINDER*/ /*****************************************/ const CRhinoLayer& layer = context.m_doc.m_layer_table.CurrentLayer(); ON_SimpleArray<CRhinoObject*> objects; int object_count = context.m_doc.LookupObject( layer, objects ); const CRhinoBrepObject* brep_obj; const CRhinoCurveObject* curve_obj; const CRhinoSurfaceObject* surface_obj; int surf_count=0; if( object_count > 0 ) { int brep_obj_count = 0; int polycurve_count = 0; const CRhinoObject* object = 0; for(int i = 0; i < object_count; i++ ) { object = objects[ i ]; /************************************/ /*TRY CASTING AS A RHINO BREP OBJECT*/ /************************************/ brep_obj = CRhinoBrepObject::Cast( object ); if( brep_obj && object->IsSolid()) { brep_obj_count++; } /*******************************/ /*TRY CASTING AS A CURVE OBJECT*/ /*******************************/ curve_obj = CRhinoCurveObject::Cast( object ); if( curve_obj ) { polycurve_count++; } //surface_obj = CRhinoSurfaceObject::Cast( object ); // if( surface_obj ) // { //surf_count++; // } } if( brep_obj_count == 0) { ON_3dPoint center_point( 0.0, 0.0, 0.0 ); double radius = 63.5; int __count = plugin.m_dialog->m_comboAltTacco.GetCount(); int nIndex = plugin.m_dialog->m_comboAltTacco.GetCurSel(); CString strCBText; plugin.m_dialog->m_comboAltTacco.GetLBText( nIndex, strCBText); int height = _wtoi(strCBText); ON_3dPoint height_point( 0.0, 0.0, height); ON_3dVector zaxis = height_point - center_point; ON_Plane planeCir( center_point, zaxis ); /*ADD CIRCLE FOR CYLINDER'S BASE*/ ON_Circle circle( planeCir, radius ); /*ADD CYLINDER*/ ON_Cylinder cylinder( circle, zaxis.Length() ); ON_Brep* brep = ON_BrepCylinder( cylinder, TRUE, TRUE ); unsigned int first_SN; unsigned int next_SN; if( brep ) { first_SN = CRhinoObject::NextRuntimeObjectSerialNumber(); /********************/ /*TRANSLATE CYLINDER*/ /********************/ int nIndex1 = plugin.m_dialog->AltezzaFondelloControllo.GetCurSel(); CString strCBText1; plugin.m_dialog->AltezzaFondelloControllo.GetLBText( nIndex1, strCBText1); int altfondello = _wtoi(strCBText1); ON_wString obj_nameCyl = L"CILINDRO"; brep->Translate(ON_3dVector( 0.0, 0.0, -altfondello)); CRhinoBrepObject* cylinder_object = new CRhinoBrepObject(); cylinder_object->SetBrep( brep ); if( context.m_doc.AddObject(cylinder_object) ) { context.m_doc.Redraw(); next_SN = CRhinoObject::NextRuntimeObjectSerialNumber(); if( first_SN == next_SN ) { return CRhinoCommand::nothing; } else { SetNametoObject(context.m_doc,first_SN,obj_nameCyl,true); } } else { delete cylinder_object; } /*********************************************/ /* DA SISTEMARE */ /*********************************************/ CRhinoSnapContext snap; bool dec1 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, (height - altfondello))); bool dec2 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, -altfondello)); bool dec3 = snap.SnapToPoint(ON_3dPoint(63.5, 0.0, 0.0)); if(dec1 && dec2) { CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension(); ON_Plane plane( ON_zx_plane ); plane.SetOrigin( ON_3dPoint(63.5, 0.0, 0.0) ); dim_obj->SetPlane( plane ); ON_3dPoint pt_1(63.5, 0.0, (height - altfondello)); ON_3dPoint pt_2(63.5, 0.0, -altfondello); double u, v; plane.ClosestPointTo( pt_1, &u, &v ); dim_obj->SetPoint( 0, ON_2dPoint(u, v) ); dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) ); plane.ClosestPointTo( pt_2, &u, &v ); dim_obj->SetPoint( 2, ON_2dPoint(u, v) ); dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) ); dim_obj->UpdateText(); if( context.m_doc.AddObject(dim_obj) ) { context.m_doc.Redraw(); } else { delete dim_obj; } } /*********************************************/ /* DA SISTEMARE */ /*********************************************/ if(dec2 && dec3) { CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension(); ON_Plane plane( ON_zx_plane ); plane.SetOrigin( ON_3dPoint(63.5, 0.0, 0.0) ); dim_obj->SetPlane( plane ); ON_3dPoint pt_1(63.5, 0.0, 0.0); ON_3dPoint pt_2(63.5, 0.0, -altfondello); double u, v; plane.ClosestPointTo( pt_1, &u, &v ); dim_obj->SetPoint( 0, ON_2dPoint(u, v) ); dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) ); plane.ClosestPointTo( pt_2, &u, &v ); dim_obj->SetPoint( 2, ON_2dPoint(u, v) ); dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) ); dim_obj->UpdateText(); if( context.m_doc.AddObject(dim_obj) ) { context.m_doc.Redraw(); } else { delete dim_obj; } } /*********************************************/ /* DA SISTEMARE By Nello */ /*********************************************/ ON_3dPoint provapunto2 = AltezzaTacco; ON_3dPoint provapunto(59.5,0,provapunto2.z); provapunto.z-=0.7; ON_3dPoint pt_1(59.5, 0.0, (height - altfondello)); CRhinoLinearDimension* dim_obj = new CRhinoLinearDimension(); ON_Plane plane( ON_zx_plane ); plane.SetOrigin(pt_1); dim_obj->SetPlane( plane ); //ON_3dPoint pt_1(63.5, 0.0, 0.0); ON_3dPoint pt_2 = provapunto; double u, v; plane.ClosestPointTo( pt_1, &u, &v ); dim_obj->SetPoint( 0, ON_2dPoint(u, v) ); dim_obj->SetPoint( 1, ON_2dPoint(u, (v + height/2)) ); plane.ClosestPointTo( pt_2, &u, &v ); dim_obj->SetPoint( 2, ON_2dPoint(u, v) ); dim_obj->SetPoint( 3, ON_2dPoint(u, (v + height/2)) ); dim_obj->UpdateText(); if( context.m_doc.AddObject(dim_obj) ) { context.m_doc.Redraw(); } else { delete dim_obj; } /*INIZIO FUNZIONE CONTROLLO*/ if ( (height - altfondello)>=provapunto.z+10){ ::RhinoApp().Print( L"Funzione controllo altezza OK"); } else{ ::RhinoApp().Print( L"Funzione controllo altezza NOK: CONTROLLARE!! Il valore della testa e' minore del valore minimo di 10 mm. Occorre diminuire l'altezza del fondello o aumentare l'altezza dello stampo."); } /*********************************************/ /* CREATE FONDELLO PLANE */ /*********************************************/ ON_3dPoint point0((63.5 + 20.0),0.0, 0.0); ON_3dPoint point1(-(63.5 + 20.0),0.0, 0.0); ON_LineCurve curve0( point0, point1 ); context.m_doc.AddCurveObject(curve0); context.m_doc.Redraw(); /******************************************************/ /*****************************/ /*USER GIVES NAME TO SURFACES*/ /*****************************/ unsigned int first_sn; unsigned int next_sn; ON_wString obj_name; object_count = context.m_doc.LookupObject( layer, objects ); for(int i = 0; i < object_count; i++ ) { object = objects[ i ]; first_sn = CRhinoObject::NextRuntimeObjectSerialNumber(); /*******************************/ /*TRY CASTING AS A CURVE OBJECT*/ /*******************************/ curve_obj = CRhinoCurveObject::Cast( object ); if( curve_obj ) { const ON_Geometry* geo = curve_obj->Geometry(); const ON_Curve* curve00 = ON_Curve::Cast(geo); ON_3dPoint point = curve00->PointAt(0.0); ON_3dPoint point_ = curve00->PointAt(1.0); if((point.z + point_.z)/2 > 0.0) { obj_name = L"SURFPV"; } else { obj_name = L"SURFFO"; } ON_3dPoint point0(point.x, (point.y + 70.0), point.z); ON_3dPoint point1(point.x, (point.y - 70.0), point.z); ON_LineCurve* curve = new ON_LineCurve(); curve->SetStartPoint(point0); curve->SetEndPoint(point1); ON_SumSurface sumSurf0; sumSurf0.Create(*curve, *curve00); if( context.m_doc.AddSurfaceObject(sumSurf0) ) { context.m_doc.Redraw(); next_sn = CRhinoObject::NextRuntimeObjectSerialNumber(); if( first_sn == next_sn ) { return CRhinoCommand::nothing; } else { SetNametoObject(context.m_doc,first_sn,obj_name,true); } } } }/*CLOSED FOR*/ //int R = 0; //object_count = context.m_doc.LookupObject( layer, objects ); //for(int i = 0; i < object_count; i++) //{ // object = objects[ i ]; // const CRhinoCurveObject* surface_obj = CRhinoCurveObject::Cast(object); // if(surface_obj) // { // R++; // } //} // // Get the string entered by the user // ON_wString obj_name = gs.String(); // obj_name.TrimLeftAndRight(); // // // Is name the same? // if( obj_name.Compare(obj_attribs.m_name) == 0 ) //return CRhinoCommand::nothing; // // // Modify the attributes of the object // obj_attribs.m_name = obj_name; // context.m_doc.ModifyObjectAttributes( objref, obj_attribs ); // if(selectobjectbyuuid_s(context.m_doc,obj_Surf[j],false)) // { //int R = 0; // } ON_wString obj_Surf[2]; ON_wString name; obj_Surf[0] = L"SURFPV"; obj_Surf[1] = L"SURFFO"; object_count = context.m_doc.LookupObject( layer, objects ); int R = 0; /************************/ /*TRY SPLITTING THE BREP*/ /************************/ for(int j = 0; j < 2; j++) { for(int i = 0; i < object_count; i++) { object = objects[ i ]; /*MAKE COPY OF OBJECT ATTRIBUTES. THIS OBJECTS*/ /*HOLDS AN OBJECT'S USER-DEFINED NAME.*/ ON_3dmObjectAttributes obj_attribs = object->Attributes(); name = object->Attributes().m_name; surface_obj = CRhinoSurfaceObject::Cast( object ); if( surface_obj && !surface_obj->IsSolid()) { ON_wString obj_SurfLoc = obj_Surf[j]; /*IS THE CUTTING SURFACE?*/ if( obj_SurfLoc.Compare(name) == 0 ) { R++; } }/*CHIUSURA IF SUPERFICIE*/ } // /************************/ // /*PICK THE BREP TO SPLIT*/ // /************************/ // CRhinoGetObject go; // go.SetCommandPrompt( L"SELECT SOLID TO SPLIT" ); // go.SetGeometryFilter( CRhinoGetObject::polysrf_object );//CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object // go.GetObjects( 1, 1 ); // if( go.CommandResult() != success ) // { //return go.CommandResult(); // } // else // { // RhinoMessageBox(L"CYLINDER IS SELECTED", PlugIn()->PlugInName(), MB_OK | MB_ICONEXCLAMATION ); // } // // const CRhinoObjRef& split_ref = go.Object(0); // // const CRhinoObject* split_object = split_ref.Object(); // if( !split_object ) // { //return failure; // } // // const ON_Brep* split = split_ref.Brep(); // if( !split ) // { //return failure; // } // ON_SimpleArray<ON_Brep*> pieces; // double tol = context.m_doc.AbsoluteTolerance(); // /***********************/ // /*PICK THE CUTTING BREP*/ // /***********************/ // go.SetCommandPrompt( L"SELECT CUTTING SURFACE OR POLYSUFACE" ); // go.SetGeometryFilter( CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object ); // go.EnablePreSelect( FALSE ); // go.EnableDeselectAllBeforePostSelect( FALSE ); // go.GetObjects( 1, 2 ); // if( go.CommandResult() != success ) // { //return go.CommandResult(); // } // const ON_Brep* cutter = go.Object(0).Brep(); // if( !cutter ) // { //return failure; // } // // if( !RhinoBrepSplit(*split, *cutter, tol, pieces) ) // { //RhinoApp().Print( L"UNABLE TO SPLIT BREP.\n" ); // } // // int i, count = pieces.Count(); // if( count == 0 | count == 1 ) // { //if( count == 1 ) //{ // delete pieces[0]; //} //return nothing; // } // // CRhinoObjectAttributes attrib = split_object->Attributes(); // attrib.m_uuid = ON_nil_uuid; // // const CRhinoObjectVisualAnalysisMode* vam_list = split_object->m_analysis_mode_list; // // for( i = 0; i < count; i++ ) // { //CRhinoBrepObject* brep_object = new CRhinoBrepObject( attrib ); //if( brep_object ) //{ // brep_object->SetBrep( pieces[i] ); // if( context.m_doc.AddObject(brep_object) ) // { // RhinoCopyAnalysisModes( vam_list, brep_object ); // } // else // { // delete brep_object; // } //} // } // // context.m_doc.DeleteObject( split_ref ); // context.m_doc.Redraw(); } /*CREATE A NEW LAYER*/ ON_Layer layer; int layer_index = 0; ON_Color color = ON_Color(0, 0, 0); ON_wString layer_name_FONDELLO = L"FONDELLO"; layer.SetLayerName( layer_name_FONDELLO ); layer.SetPlotColor(color.Green()); /*ADD THE LAYER TO THE LAYER TABLE*/ layer_index = context.m_doc.m_layer_table.AddLayer( layer ); ON_wString layer_name_MATRICE = L"MATRICE"; layer.SetLayerName( layer_name_MATRICE ); layer.SetColor(color.Red()); /*ADD THE LAYER TO THE LAYER TABLE*/ layer_index = context.m_doc.m_layer_table.AddLayer( layer ); ON_wString layer_name_FISSO = L"FISSO"; layer.SetLayerName( layer_name_FISSO ); layer.SetColor(color.Blue()); /*ADD THE LAYER TO THE LAYER TABLE*/ layer_index = context.m_doc.m_layer_table.AddLayer( layer ); context.m_doc.Redraw(); /*********************************************************/ } }/*CLOSED IF OVER CHECKING BREP COUNT OBJECT*/ else { RhinoMessageBox(L"THERE IS ALREADY A CYLINDER OBJECT", PlugIn()->PlugInName(), MB_OK | MB_ICONEXCLAMATION ); } } /**********************************************************************/ return CRhinoCommand::success; }