<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Qt3D picking triangles]]></title><description><![CDATA[<p dir="auto">I've been trying to get triangle data for a good while now using Qt3D in C++ with no success. I have been able to get the PickEvent to work and it's data is correct but I don't know how to get the PickTriangleEvent. I've search all over the place but was only able to find one example on getting the triangle data and it was in QML - when I tried the same thing in C++ it didn't work.</p>
<p dir="auto">Currently, this is how I'm getting the PickEvent data.</p>
<p dir="auto">I add the QObjectPicker component to the mesh object.<br />
connect the signal</p>
<pre><code>connect(m_pObjectPicker,SIGNAL(clicked(Qt3DRender::QPickEvent*)),this,SLOT(clicked(Qt3DRender::QPickEvent*)));
</code></pre>
<p dir="auto">The clicked slot looks like this:</p>
<pre><code>void Mesh::clicked(Qt3DRender::QPickEvent* event){ ... }
</code></pre>
<p dir="auto">My pick settings are already set to triangles:</p>
<pre><code>m_pFrameGraph-&gt;pickingSettings()-&gt;setPickMethod(Qt3DRender::QPickingSettings::TrianglePicking);
m_pFrameGraph-&gt;pickingSettings()-&gt;setPickResultMode(Qt3DRender::QPickingSettings::AllPicks);
</code></pre>
<p dir="auto">And this all works fine except when trying to get the triangle data.</p>
]]></description><link>https://forum.qt.io/topic/71893/qt3d-picking-triangles</link><generator>RSS for Node</generator><lastBuildDate>Sun, 03 May 2026 06:32:49 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/71893.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 03 Oct 2016 18:31:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Qt3D picking triangles on Mon, 29 Oct 2018 08:36:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/unclejimbo-0">@<bdi>unclejimbo-0</bdi></a>  Hello. My Entity is imported with <code>Qt3DRender::QSceneLoader</code> like this:</p>
<pre><code>m_sceneLoaderEntity = new Qt3DCore::QEntity();

 Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader(m_sceneLoaderEntity);

// EditorSceneItemModel::handleImportEntityLoaderStatusChanged is a slot developed to react to a signal when import operation is finished
QObject::connect(sceneLoader, &amp;Qt3DRender::QSceneLoader::statusChanged,
                     this, &amp;EditorSceneItemModel::handleImportEntityLoaderStatusChanged);

sceneLoader-&gt;setSource(fileUrl);

m_sceneLoaderEntity-&gt;addComponent(sceneLoader);
</code></pre>
<p dir="auto">So, it might be considered as custom mesh! I think picking triangles should work fine with custom meshes. By the way, I'm working with <strong>Qt 5.11.2</strong></p>
]]></description><link>https://forum.qt.io/post/489698</link><guid isPermaLink="true">https://forum.qt.io/post/489698</guid><dc:creator><![CDATA[m3g1dd]]></dc:creator><pubDate>Mon, 29 Oct 2018 08:36:29 GMT</pubDate></item><item><title><![CDATA[Reply to Qt3D picking triangles on Thu, 25 Oct 2018 15:05:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/m3g1dd">@<bdi>m3g1dd</bdi></a> Hi, is your QGeometryRenderer component a built-in mesh in Qt3SDExtras or is it a custom mesh?</p>
<p dir="auto">I've got some troubles picking triangles for a custom mesh built from QGeometry, QAttribute and QBuffer. The clicked event never trigers. But when I use a built-in mesh like QSphereMesh it works fine. Any idea how to do triangle picking for custom meshes?</p>
]]></description><link>https://forum.qt.io/post/489000</link><guid isPermaLink="true">https://forum.qt.io/post/489000</guid><dc:creator><![CDATA[unclejimbo 0]]></dc:creator><pubDate>Thu, 25 Oct 2018 15:05:25 GMT</pubDate></item><item><title><![CDATA[Reply to Qt3D picking triangles on Thu, 25 Oct 2018 10:46:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rlayman">@<bdi>RLayman</bdi></a> I had the same problem, I had this method to add <code>Qt3DRender::QObjectPicker</code> to my entities:</p>
<pre><code>Qt3DRender::QObjectPicker *EditorScene::createObjectPickerForEntity(Qt3DCore::QEntity *entity)
{
    Qt3DRender::QObjectPicker *picker = new Qt3DRender::QObjectPicker(entity);
    entity-&gt;addComponent(picker);
    connect(picker, &amp;Qt3DRender::QObjectPicker::pressed, this, &amp;EditorScene::handlePickerPress);
return picker;
}
</code></pre>
<p dir="auto">My rendering settings <code>Qt3DRender::QRenderSettings</code> are added to entities like this, note that the <code>PickMethod</code> must be <code>TrianglePicking</code>:</p>
<pre><code>m_renderSettings = new Qt3DRender::QRenderSettings();
    m_renderSettings-&gt;pickingSettings()-&gt;setPickMethod(Qt3DRender::QPickingSettings::TrianglePicking);
    m_renderSettings-&gt;pickingSettings()-&gt;setPickResultMode(Qt3DRender::QPickingSettings::NearestPick);

entity-&gt;addComponent(m_renderSettings);

</code></pre>
<p dir="auto">And I had this code to handle click press events I was able to print click position/location by <code>event-&gt;worldIntersection()</code>  but i didn't know how to get the index of clicked triangle. Finally, I managed to print the index of clicked triangle by casting <code>Qt3DRender::QPickEvent *</code> as <code>Qt3DRender::QPickTriangleEvent *</code>:</p>
<pre><code>void EditorScene::handlePickerPress(Qt3DRender::QPickEvent *event)
{
    // // "event" will give me clicked coordinates like this:
    qDebug() &lt;&lt; __func__ &lt;&lt; ": global Coord: " &lt;&lt; event-&gt;worldIntersection();
    
    // // Also I can get picked/clicked triangle index and its vertices by casting event pointer type:
    Qt3DRender::QPickTriangleEvent *eventTri = static_cast&lt;Qt3DRender::QPickTriangleEvent *&gt;(event);
    qDebug() &lt;&lt; __func__ &lt;&lt; "Pick Triangle Index: " &lt;&lt; eventTri-&gt;triangleIndex();
    qDebug() &lt;&lt; __func__ &lt;&lt; "Pick Triangle Vertex 1: " &lt;&lt; eventTri-&gt;vertex1Index();
    qDebug() &lt;&lt; __func__ &lt;&lt; "Pick Triangle Vertex 2: " &lt;&lt; eventTri-&gt;vertex2Index();
    qDebug() &lt;&lt; __func__ &lt;&lt; "Pick Triangle Vertex 3: " &lt;&lt; eventTri-&gt;vertex3Index();
}
</code></pre>
]]></description><link>https://forum.qt.io/post/488940</link><guid isPermaLink="true">https://forum.qt.io/post/488940</guid><dc:creator><![CDATA[m3g1dd]]></dc:creator><pubDate>Thu, 25 Oct 2018 10:46:25 GMT</pubDate></item></channel></rss>