File indexing completed on 2025-01-26 05:19:14
0001 /* Atelier KDE Printer Host for 3D Printing 0002 Copyright (C) <2017-2018> 0003 Author: Patrick José Pereira - patrickjp@kde.org 0004 Kevin Ottens - ervin@kde.org 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 3 of 0009 the License or any later version accepted by the membership of 0010 KDE e.V. (or its successor approved by the membership of KDE 0011 e.V.), which shall act as a proxy defined in Section 14 of 0012 version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include "linemeshgeometry.h" 0024 #include <QVector3D> 0025 #include <QVector> 0026 0027 LineMeshGeometry::LineMeshGeometry(const QVector<QVector3D> &vertices, Qt3DCore::QNode *parent) 0028 : Qt3DRender::QGeometry(parent) 0029 , _positionAttribute(new Qt3DRender::QAttribute(this)) 0030 , _vertexBuffer(new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, this)) 0031 { 0032 QByteArray vertexBufferData; 0033 vertexBufferData.resize(vertices.size() * static_cast<int>(sizeof(QVector3D))); 0034 memcpy(vertexBufferData.data(), vertices.constData(), static_cast<size_t>(vertexBufferData.size())); 0035 _vertexBuffer->setData(vertexBufferData); 0036 0037 _positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); 0038 _positionAttribute->setBuffer(_vertexBuffer); 0039 _positionAttribute->setDataType(Qt3DRender::QAttribute::Float); 0040 _positionAttribute->setDataSize(3); 0041 _positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); 0042 0043 addAttribute(_positionAttribute); 0044 } 0045 0046 int LineMeshGeometry::vertexCount() 0047 { 0048 return _vertexBuffer->data().size() / static_cast<int>(sizeof(QVector3D)); 0049 }