Commit 508dde94 authored by Sami Varanka's avatar Sami Varanka
Browse files

nothing

parent 9be6ea19
......@@ -19,7 +19,7 @@ QByteArray CppInstancing::getInstanceBuffer(int *instanceCount)
int instanceNumber = 0;
for (const auto &pos : qAsConst(m_positions)) {
auto entry = calculateTableEntry(pos, {0.01f, 0.01f, 0.01f}, {}, QColor(Qt::white));
auto entry = calculateTableEntry(pos, {1,1,1}, {}, QColor(Qt::white));
m_instanceData.append(reinterpret_cast<char *>(&entry), sizeof(entry));
instanceNumber++;
}
......@@ -43,4 +43,5 @@ void CppInstancing::setPositions(const QList<QVector3D> &newPositions)
{
m_positions = newPositions;
m_dirty = true;
markDirty();
}
......@@ -12,9 +12,11 @@ Foo::Foo(QQuickItem *parent)
auto env = environment();
env->setClearColor(QColor(Qt::green));
env->setBackgroundMode(QQuick3DSceneEnvironment::Color);
// auto light = new QQuick3DDirectionalLight();
// light->setParent(scene());
// light->setParentItem(scene());
m_light = new QQuick3DDirectionalLight();
m_light->setParent(scene());
m_light->setParentItem(scene());
}
Foo::~Foo()
......@@ -90,6 +92,33 @@ void Foo::useInstancing()
}
}
void Foo::selectOneInstance()
{
auto selectedPosition = m_positions.takeAt(3);
qDebug()<<"Took position"<<selectedPosition;
m_highlightedIndex = 3;
m_highlighted->setPosition(selectedPosition);
m_highlighted->setVisible(true);
m_instancing->setPositions(m_positions);
}
void Foo::unselectOneInstance()
{
auto pos = m_highlighted->position();
m_positions.insert(m_highlightedIndex, pos);
m_highlighted->setVisible(false);
m_instancing->setPositions(m_positions);
}
void Foo::setLabelPosition(const QVector3D &position)
{
if (m_labelNode)
m_labelNode->setPosition(position);
else
qWarning()<<__func__<<"label node not created";
}
int Foo::positionCount() const
{
return m_positionCount;
......@@ -113,12 +142,36 @@ QVector3D Foo::randomPosition()
void Foo::generatePositions()
{
QList<QVector3D> positions;
positions.resize(m_positionCount);
m_positions.resize(m_positionCount);
for (int i = 0; i < m_positionCount; ++i) {
positions[i] = randomPosition();
m_positions[i] = randomPosition();
}
m_instancing->setPositions(positions);
m_instancing->setPositions(m_positions);
}
void Foo::createLabel()
{
auto labelNode = new QQuick3DNode();
labelNode->setParent(scene());
labelNode->setParentItem(scene());
}
void Foo::componentComplete()
{
QQuick3DViewport::componentComplete();
m_highlighted = new QQuick3DModel();
m_highlighted->setParent(scene());
m_highlighted->setParentItem(scene());
m_highlighted->setSource(QUrl(QStringLiteral("#Sphere")));
auto material = new QQuick3DPrincipledMaterial();
material->setBaseColor(QColor(Qt::red));
QQmlListReference materialsRef(m_highlighted, "materials");
materialsRef.append(material);
m_highlighted->setVisible(false);
}
......@@ -2,6 +2,7 @@
#define FOO_H
#include <QtQml/qqml.h>
#include <QtQuick3D/private/qquick3dviewport_p.h>
#include <QtQuick3D/private/qquick3ddirectionallight_p.h>
class CppInstancing;
......@@ -22,6 +23,9 @@ public:
Q_INVOKABLE void removeSphere();
Q_INVOKABLE void squeezeSpheresList();
Q_INVOKABLE void useInstancing();
Q_INVOKABLE void selectOneInstance();
Q_INVOKABLE void unselectOneInstance();
Q_INVOKABLE void setLabelPosition(const QVector3D &position);
int positionCount() const;
void setPositionCount(int newPositionCount);
......@@ -33,15 +37,27 @@ signals:
private:
QVector3D randomPosition();
void generatePositions();
void createLabel();
private:
int m_bar = 0;
int m_positionCount = 0;
QList<QVector3D> m_positions;
CppInstancing *m_instancing = nullptr;
int m_highlightedIndex = -1;
QQuick3DModel *m_instanceRoot = nullptr;
QQuick3DModel *m_highlighted = nullptr;
QList<QQuick3DModel *> m_spheres;
QQuick3DDirectionalLight *m_light = nullptr;
QQuick3DNode *m_labelNode;
// QQmlParserStatus interface
public:
void componentComplete() override;
};
#endif // FOO_H
......@@ -20,12 +20,16 @@ Window {
foo.squeezeSpheresList()
else if (event.key === Qt.Key_I)
foo.useInstancing()
else if (event.key === Qt.Key_O)
foo.selectOneInstance();
else if (event.key === Qt.Key_P)
foo.unselectOneInstance()
}
Foobar {
id: foo
anchors.fill: parent
camera: camera
positionCount: 500
positionCount: 10
}
......@@ -36,7 +40,7 @@ Window {
PerspectiveCamera {
id: camera
position: Qt.vector3d(0,0,0)
position: Qt.vector3d(0,0,600)
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment