Skip to content

Commit 560199e

Browse files
committed
fixing 2nd mesh rendering
Signed-off-by: Perminder <[email protected]>
1 parent 2d772c3 commit 560199e

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

avogadro/qtplugins/meshes/meshes.cpp

+25-17
Original file line numberDiff line numberDiff line change
@@ -66,52 +66,60 @@ void Meshes::process(const QtGui::Molecule& mol, GroupNode& node)
6666
auto* geometry = new GeometryNode;
6767
node.addChild(geometry);
6868

69+
// Handle the first mesh
6970
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();
7572

7673
bool hasColors = (mesh->colors().size() != 0);
7774

7875
auto* mesh1 = new MeshGeometry;
7976
geometry->addDrawable(mesh1);
8077
mesh1->setOpacity(m_opacity);
78+
8179
if (hasColors) {
8280
auto colors = mesh->colors();
8381
Core::Array<Vector3ub> colorsRGB(colors.size());
8482
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));
8786
mesh1->addVertices(mesh->vertices(), mesh->normals(), colorsRGB);
8887
} 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());
9190
}
91+
92+
// Add the triangles for the first mesh
9293
for (size_t i = 0; i < triangles.size(); ++i) {
9394
mesh1->addTriangle(triangles[i][0], triangles[i][1], triangles[i][2]);
9495
}
95-
mesh1->setRenderPass(m_opacity == 255 ? Rendering::SolidPass
96-
: Rendering::TranslucentPass);
9796

98-
if (mol.meshCount() >= 2) { // it's a molecular orbital, two parts
97+
mesh1->setRenderPass(m_opacity == 255 ? Rendering::SolidPass : Rendering::TranslucentPass);
9998

99+
// Handle the second mesh if present
100+
if (mol.meshCount() >= 2) {
100101
auto* mesh2 = new MeshGeometry;
101102
geometry->addDrawable(mesh2);
103+
102104
mesh = mol.mesh(1);
105+
106+
// Retrieve the second mesh’s triangles
107+
Core::Array<Vector3f> triangles2 = mesh->triangles();
108+
103109
mesh2->setColor(m_color2);
104110
mesh2->setOpacity(m_opacity);
105111
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+
109118
mesh2->setRenderPass(m_opacity == 255 ? Rendering::SolidPass
110119
: Rendering::TranslucentPass);
111120
}
112121
}
113-
}
114-
122+
}
115123

116124
void Meshes::setOpacity(int opacity)
117125
{

0 commit comments

Comments
 (0)