[Interest] QQuick3DGeometry example not working
joao morgado
joaodeusmorgado at yahoo.com
Sun Sep 27 03:23:29 CEST 2020
I'm trying to draw a line using QQuick3DGeometry but nothing is draw.
I couldnt find a working example of QQuick3DGeometry, if anyone knows please share.
Also I dont need normals for a line, but not using them gives me a warning: QSSG.warning: Failed to bind attribute attr_norm
The full code example I did:
https://drive.google.com/file/d/1trroeJ_xXjwbW8M1CKiy3WXAVtOl8UHQ/view?usp=sharing
The relevant code:
//--------------------------------------------------------------------
class Entity_Line : public QQuick3DGeometry
{
Q_OBJECT
Q_PROPERTY(QVector3D p0 READ p0 WRITE setP0 NOTIFY p0Changed)
Q_PROPERTY(QVector3D p1 READ p1 WRITE setP1 NOTIFY p1Changed)
public:
Entity_Line(QQuick3DObject *ptr = nullptr);
//~Entity_Line();
QVector3D p0() const {return m_P0;}
QVector3D p1() const {return m_P1;}
public slots:
void setP0(const QVector3D &p0);
void setP0(const float &px, const float &py, const float &pz);
void setP1(const QVector3D &p1);
void setP1(const float &px, const float &py, const float &pz);
Q_INVOKABLE void setupGeometry();
signals:
void p0Changed(QVector3D newP0);
void p1Changed(QVector3D newP1);
private:
QVector3D m_P0;
QVector3D m_P1;
};
//---------------------------------------------------------------------------
Entity_Line::Entity_Line(QQuick3DObject *ptr) :
QQuick3DGeometry(ptr)
{
setName("line");
setP0(-50, -50, -10);
setP1(50, 50, 10);
setupGeometry();
}
void Entity_Line::setP0(const QVector3D &p0)
{
if (m_P0 == p0)
return;
m_P0 = p0;
emit p0Changed(p0);
}
void Entity_Line::setP0(const float &px, const float &py, const float &pz)
{
QVector3D v(px, py, pz);
setP0(v);
}
void Entity_Line::setP1(const QVector3D &p1)
{
qDebug()<<"setP1(const QVector3D &p1)........................................."<<p1.x();
if (m_P1 == p1)
return;
m_P1 = p1;
emit p1Changed(p1);
}
void Entity_Line::setP1(const float &px, const float &py, const float &pz)
{
QVector3D v(px, py, pz);
setP1(v);
}
void Entity_Line::setupGeometry()
{
QByteArray vertices;
QByteArray indices;
vertices.clear();
vertices.resize(2*sizeof(QVector3D));
vertices.append(m_P0.x());
vertices.append(m_P0.y());
vertices.append(m_P0.z());
vertices.append(m_P1.x());
vertices.append(m_P1.y());
vertices.append(m_P1.z());
uint i;
indices.clear();
i = 0;
indices.append(i);
i = 1;
indices.append(i);
//fillGeometry(vertices, indices);
setPrimitiveType(PrimitiveType::Lines);
setVertexData(vertices.constData());
setIndexData(indices);
//setStride(sizeof(QVector3D));
qDebug()<<"stride size: "<<2*sizeof(QVector3D)+sizeof(uint);
setStride(2*sizeof(QVector3D)+sizeof(uint));
setBounds(m_P0, m_P1);
addAttribute(Attribute::PositionSemantic, 0, Attribute::F32Type);
addAttribute(Attribute::IndexSemantic, 2*sizeof(QVector3D), Attribute::U32Type);
//addAttribute(Attribute::NormalSemantic, 2*sizeof(QVector3D)+sizeof(uint), Attribute::F32Type);
//I dont need normals but without the above line I get a warning: QSSG.warning: Failed to bind attribute attr_norm
qDebug()<<"attributeCount: "<<attributeCount();
}
//---------------------------
ThanksJoão
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200927/02e6108d/attachment.html>
More information about the Interest
mailing list