public override bool ExecConduit(ref MRhinoDisplayPipeline dp, uint nChannel, ref bool bTerminate) { if (nChannel == MSupportChannels.SC_DRAWOBJECT) { if (null != m_pChannelAttrs.m_pObject) { if (m_pChannelAttrs.m_pObject.m_runtime_object_serial_number == m_runtime_object_serial_number) { if (null == m_mesh_face_colors) { IRhinoMeshObject mesh_object = MRhinoMeshObject.ConstCast(m_pChannelAttrs.m_pObject); if (null != mesh_object) { int mesh_face_count = mesh_object.Mesh().FaceCount(); m_mesh_face_colors = new ArrayOnColor(mesh_face_count); for (int i = 0; i < mesh_face_count; i++) { OnColor color = new OnColor(m_random.Next(0, 255), m_random.Next(0, 255), m_random.Next(0, 255)); m_mesh_face_colors.Append(color); } } } if (null != m_mesh_face_colors) { m_pChannelAttrs.m_bDrawObject = false; MDisplayPipelineAttributes da = new MDisplayPipelineAttributes(); da.m_bShadeSurface = true; da.m_pMaterial.m_FrontMaterial.SetTransparency(0.0); da.m_pMaterial.m_BackMaterial.SetTransparency(0.0); da.m_pMaterial.m_FrontMaterial.m_bFlatShaded = true; da.m_pMaterial.m_BackMaterial.m_bFlatShaded = true; dp.EnableDepthWriting(true); if (da.m_bCullBackfaces) { dp.PushCullFaceMode(1); } for (int i = 0; i < m_mesh_face_colors.Count(); i++) { da.m_pMaterial.m_FrontMaterial.m_diffuse = m_mesh_face_colors[i]; da.m_pMaterial.m_BackMaterial.m_diffuse = m_mesh_face_colors[i]; dp.DrawFace(m_pChannelAttrs.m_pObject, i, da); } if (da.m_bCullBackfaces) { dp.PopCullFaceMode(); } } } } } return(true); }
/// <summary> /// MRhinoVisualAnalysisMode override /// </summary> public override void UpdateVertexColors(IRhinoObject obj, OnMesh[] meshes) { // Rhino calls this function when it is time for you // to set the false colors on the analysis mesh vertices. // For breps, there is one mesh per face. For mesh objects, // there is a single mesh. int count = meshes.Length; if (count > 0) { // A "mapping tag" is used to determine if the colors need to be set OnMappingTag mt = MappingTag(); for (int mi = 0; mi < count; mi++) { OnMesh mesh = meshes[mi]; if (null != mesh && 0 != mt.Compare(mesh.m_Ctag)) { // The mesh's mapping tag is different from ours. Either // the mesh has no false colors, has false colors set by // another analysis mode, has false colors set using // different m_z_range[]/m_hue_range[] values, or the // mesh has been moved. In any case, we need to set // the false colors to the ones we want. int vcount = mesh.m_V.Count(); ArrayOnColor vertex_colors = mesh.m_C; vertex_colors.SetCount(0); // in case something else had set the colors vertex_colors.Reserve(vcount); // for efficiency for (int vi = 0; vi < vcount; vi++) { double z = mesh.m_V[vi].z; OnColor color = FalseColor(z); vertex_colors.Append(color); } // set the mesh's color tag mesh.m_Ctag = mt; } } } }
public override bool ExecConduit(ref MRhinoDisplayPipeline dp, uint nChannel, ref bool bTerminate) { if (nChannel == MSupportChannels.SC_DRAWOBJECT) { if (null != m_pChannelAttrs.m_pObject) { if (m_pChannelAttrs.m_pObject.m_runtime_object_serial_number == m_runtime_object_serial_number) { if (null == m_mesh_face_colors) { IRhinoMeshObject mesh_object = MRhinoMeshObject.ConstCast(m_pChannelAttrs.m_pObject); if (null != mesh_object) { int mesh_face_count = mesh_object.Mesh().FaceCount(); m_mesh_face_colors = new ArrayOnColor(mesh_face_count); for (int i = 0; i < mesh_face_count; i++) { OnColor color = new OnColor(m_random.Next(0, 255), m_random.Next(0, 255), m_random.Next(0, 255)); m_mesh_face_colors.Append(color); } } } if (null != m_mesh_face_colors) { m_pChannelAttrs.m_bDrawObject = false; MDisplayPipelineAttributes da = new MDisplayPipelineAttributes(); da.m_bShadeSurface = true; da.m_pMaterial.m_FrontMaterial.SetTransparency(0.0); da.m_pMaterial.m_BackMaterial.SetTransparency(0.0); da.m_pMaterial.m_FrontMaterial.m_bFlatShaded = true; da.m_pMaterial.m_BackMaterial.m_bFlatShaded = true; dp.EnableDepthWriting(true); if (da.m_bCullBackfaces) dp.PushCullFaceMode(1); for (int i = 0; i < m_mesh_face_colors.Count(); i++) { da.m_pMaterial.m_FrontMaterial.m_diffuse = m_mesh_face_colors[i]; da.m_pMaterial.m_BackMaterial.m_diffuse = m_mesh_face_colors[i]; dp.DrawFace(m_pChannelAttrs.m_pObject, i, da); } if (da.m_bCullBackfaces) dp.PopCullFaceMode(); } } } } return true; }