Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Molecular orbital rendering with Flying Edges #1853

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions avogadro/qtplugins/meshes/meshes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,52 +66,60 @@ void Meshes::process(const QtGui::Molecule& mol, GroupNode& node)
auto* geometry = new GeometryNode;
node.addChild(geometry);

// Handle the first mesh
const Mesh* mesh = mol.mesh(0);

Core::Array<Vector3f> triangles;

triangles = mesh->triangles();

Core::Array<Vector3f> triangles = mesh->triangles();

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

auto* mesh1 = new MeshGeometry;
geometry->addDrawable(mesh1);
mesh1->setOpacity(m_opacity);

if (hasColors) {
auto colors = mesh->colors();
Core::Array<Vector3ub> colorsRGB(colors.size());
for (size_t i = 0; i < colors.size(); i++)
colorsRGB[i] = Vector3ub(colors[i].red() * 255, colors[i].green() * 255,
colors[i].blue() * 255);
colorsRGB[i] = Vector3ub(static_cast<unsigned char>(colors[i].red() * 255),
static_cast<unsigned char>(colors[i].green() * 255),
static_cast<unsigned char>(colors[i].blue() * 255));
mesh1->addVertices(mesh->vertices(), mesh->normals(), colorsRGB);
} else {
mesh1->setColor(m_color1);
mesh1->addVertices(mesh->vertices(), mesh->normals());
mesh1->setColor(m_color1);
mesh1->addVertices(mesh->vertices(), mesh->normals());
}

// Add the triangles for the first mesh
for (size_t i = 0; i < triangles.size(); ++i) {
mesh1->addTriangle(triangles[i][0], triangles[i][1], triangles[i][2]);
}
mesh1->setRenderPass(m_opacity == 255 ? Rendering::SolidPass
: Rendering::TranslucentPass);

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

// Handle the second mesh if present
if (mol.meshCount() >= 2) {
auto* mesh2 = new MeshGeometry;
geometry->addDrawable(mesh2);

mesh = mol.mesh(1);

// Retrieve the second mesh’s triangles
Core::Array<Vector3f> triangles2 = mesh->triangles();

mesh2->setColor(m_color2);
mesh2->setOpacity(m_opacity);
mesh2->addVertices(mesh->vertices(), mesh->normals());
for (size_t i = 0; i < triangles.size(); ++i) {
mesh2->addTriangle(triangles[i][0], triangles[i][1], triangles[i][2]);
}

// Add the correct triangles for the second mesh
for (size_t i = 0; i < triangles2.size(); ++i) {
mesh2->addTriangle(triangles2[i][0], triangles2[i][1], triangles2[i][2]);
}

mesh2->setRenderPass(m_opacity == 255 ? Rendering::SolidPass
: Rendering::TranslucentPass);
}
}
}

}

void Meshes::setOpacity(int opacity)
{
Expand Down
Loading