@@ -66,52 +66,60 @@ void Meshes::process(const QtGui::Molecule& mol, GroupNode& node)
66
66
auto * geometry = new GeometryNode;
67
67
node.addChild (geometry);
68
68
69
+ // Handle the first mesh
69
70
const Mesh* mesh = mol.mesh (0 );
70
-
71
- Core::Array<Vector3f> triangles;
72
-
73
- triangles = mesh->triangles ();
74
-
71
+ Core::Array<Vector3f> triangles = mesh->triangles ();
75
72
76
73
bool hasColors = (mesh->colors ().size () != 0 );
77
74
78
75
auto * mesh1 = new MeshGeometry;
79
76
geometry->addDrawable (mesh1);
80
77
mesh1->setOpacity (m_opacity);
78
+
81
79
if (hasColors) {
82
80
auto colors = mesh->colors ();
83
81
Core::Array<Vector3ub> colorsRGB (colors.size ());
84
82
for (size_t i = 0 ; i < colors.size (); i++)
85
- colorsRGB[i] = Vector3ub (colors[i].red () * 255 , colors[i].green () * 255 ,
86
- colors[i].blue () * 255 );
83
+ colorsRGB[i] = Vector3ub (static_cast <unsigned char >(colors[i].red () * 255 ),
84
+ static_cast <unsigned char >(colors[i].green () * 255 ),
85
+ static_cast <unsigned char >(colors[i].blue () * 255 ));
87
86
mesh1->addVertices (mesh->vertices (), mesh->normals (), colorsRGB);
88
87
} else {
89
- mesh1->setColor (m_color1);
90
- mesh1->addVertices (mesh->vertices (), mesh->normals ());
88
+ mesh1->setColor (m_color1);
89
+ mesh1->addVertices (mesh->vertices (), mesh->normals ());
91
90
}
91
+
92
+ // Add the triangles for the first mesh
92
93
for (size_t i = 0 ; i < triangles.size (); ++i) {
93
94
mesh1->addTriangle (triangles[i][0 ], triangles[i][1 ], triangles[i][2 ]);
94
95
}
95
- mesh1->setRenderPass (m_opacity == 255 ? Rendering::SolidPass
96
- : Rendering::TranslucentPass);
97
96
98
- if (mol. meshCount () >= 2 ) { // it's a molecular orbital, two parts
97
+ mesh1-> setRenderPass (m_opacity == 255 ? Rendering::SolidPass : Rendering::TranslucentPass);
99
98
99
+ // Handle the second mesh if present
100
+ if (mol.meshCount () >= 2 ) {
100
101
auto * mesh2 = new MeshGeometry;
101
102
geometry->addDrawable (mesh2);
103
+
102
104
mesh = mol.mesh (1 );
105
+
106
+ // Retrieve the second mesh’s triangles
107
+ Core::Array<Vector3f> triangles2 = mesh->triangles ();
108
+
103
109
mesh2->setColor (m_color2);
104
110
mesh2->setOpacity (m_opacity);
105
111
mesh2->addVertices (mesh->vertices (), mesh->normals ());
106
- for (size_t i = 0 ; i < triangles.size (); ++i) {
107
- mesh2->addTriangle (triangles[i][0 ], triangles[i][1 ], triangles[i][2 ]);
108
- }
112
+
113
+ // Add the correct triangles for the second mesh
114
+ for (size_t i = 0 ; i < triangles2.size (); ++i) {
115
+ mesh2->addTriangle (triangles2[i][0 ], triangles2[i][1 ], triangles2[i][2 ]);
116
+ }
117
+
109
118
mesh2->setRenderPass (m_opacity == 255 ? Rendering::SolidPass
110
119
: Rendering::TranslucentPass);
111
120
}
112
121
}
113
- }
114
-
122
+ }
115
123
116
124
void Meshes::setOpacity (int opacity)
117
125
{
0 commit comments