731 pixelData.resize(4 * numpixels); |
731 pixelData.resize(4 * numpixels); |
732 |
732 |
733 // Read pixels from the color buffer. |
733 // Read pixels from the color buffer. |
734 glReadPixels(x0, height() - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data()); |
734 glReadPixels(x0, height() - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data()); |
735 |
735 |
736 QSet<qint32> indices; |
736 QSet<qint32> ids; |
737 |
737 |
738 // Go through each pixel read and add them to the selection. |
738 // Go through each pixel read and add them to the selection. |
739 // Each pixel maps to an LDObject index injectively. |
739 // Each pixel maps to an LDObject index injectively. |
740 // Note: black is background, those indices are skipped. |
740 // Note: black is background, those indices are skipped. |
741 for (unsigned char *pixelCursor = pixelData.begin(); pixelCursor < pixelData.end(); pixelCursor += 4) |
741 for (unsigned char *pixelCursor = pixelData.begin(); pixelCursor < pixelData.end(); pixelCursor += 4) |
742 { |
742 { |
743 qint32 index = pixelCursor[0] * 0x10000 + pixelCursor[1] * 0x100 + pixelCursor[2] * 0x1; |
743 qint32 id = pixelCursor[0] * 0x10000 + pixelCursor[1] * 0x100 + pixelCursor[2] * 0x1; |
744 if (index != 0) |
744 if (id != 0) |
745 indices.insert(index); |
745 ids.insert(id); |
746 } |
746 } |
747 |
747 |
748 // For each index read, resolve the LDObject behind it and add it to the selection. |
748 // For each index read, resolve the LDObject behind it and add it to the selection. |
749 for (qint32 index : indices) |
749 for (qint32 id : ids) |
750 { |
750 { |
751 LDObject* object = LDObject::fromID(index); |
751 QModelIndex index = m_model->indexFromId(id); |
752 |
752 |
753 if (object != nullptr) |
753 if (index.isValid()) |
754 newSelection.insert(object); |
754 result.select(index, index); |
755 } |
755 } |
756 |
756 |
757 setPicking(false); |
757 setPicking(false); |
758 repaint(); |
758 repaint(); |
759 return newSelection; |
759 return result; |
760 } |
760 } |
761 |
761 |
762 /* |
762 /* |
763 * Simpler version of GLRenderer::pick which simply picks whatever object on the cursor |
763 * Simpler version of GLRenderer::pick which simply picks whatever object on the cursor |
764 */ |
764 */ |
765 LDObject* GLRenderer::pick(int mouseX, int mouseY) |
765 QModelIndex GLRenderer::pick(int mouseX, int mouseY) |
766 { |
766 { |
767 unsigned char pixel[4]; |
|
768 makeCurrent(); |
767 makeCurrent(); |
769 setPicking(true); |
768 setPicking(true); |
770 drawGLScene(); |
769 drawGLScene(); |
|
770 unsigned char pixel[4]; |
771 glReadPixels(mouseX, height() - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
771 glReadPixels(mouseX, height() - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel); |
772 LDObject* object = LDObject::fromID(pixel[0] * 0x10000 + pixel[1] * 0x100 + pixel[2]); |
772 QModelIndex result = m_model->indexFromId(pixel[0] * 0x10000 + pixel[1] * 0x100 + pixel[2]); |
773 setPicking(false); |
773 setPicking(false); |
774 repaint(); |
774 repaint(); |
775 return object; |
775 return result; |
776 } |
776 } |
777 |
777 |
778 // ============================================================================= |
778 // ============================================================================= |
779 // |
779 // |
780 void GLRenderer::setPicking(bool picking) |
780 void GLRenderer::setPicking(bool picking) |
1016 * This virtual function lets derivative classes render something to the fixed camera |
1016 * This virtual function lets derivative classes render something to the fixed camera |
1017 * before the main brick is rendered. |
1017 * before the main brick is rendered. |
1018 */ |
1018 */ |
1019 void GLRenderer::drawFixedCameraBackdrop() {} |
1019 void GLRenderer::drawFixedCameraBackdrop() {} |
1020 |
1020 |
|
1021 QItemSelectionModel* GLRenderer::selectionModel() const |
|
1022 { |
|
1023 return m_compiler->selectionModel(); |
|
1024 } |
|
1025 |
1021 void GLRenderer::setSelectionModel(QItemSelectionModel* selectionModel) |
1026 void GLRenderer::setSelectionModel(QItemSelectionModel* selectionModel) |
1022 { |
1027 { |
1023 this->m_compiler->setSelectionModel(selectionModel); |
1028 this->m_compiler->setSelectionModel(selectionModel); |
1024 } |
1029 } |