<?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[How to find the closest primitive in a mesh]]></title><description><![CDATA[<p dir="auto">I was very happy to find this nice example. Thanks Ferdinand!<br />
However looking at the docs and If I have understood this correctly,  I should be able to include &lt;distancequery.h&gt; to get access to the DistanceQueryInterface.<br />
My problem is that the &lt;distancequery.h&gt; source file is not found.<br />
All common frameworks are available to my build system.<br />
Any help or hint on what to look for would be much appreciated. I'm sure I have overlooked something trivial. <img src="http://developers.maxon.net/forum/assets/plugins/nodebb-plugin-emoji/emoji/android/1f603.png?v=0b8ddba251d" class="not-responsive emoji emoji-android emoji--smiley" style="height:23px;width:auto;vertical-align:middle" title="=)" alt="😃" /></p>
<p dir="auto">set(maxon_targetFrameworkDependencies<br />
asset.framework<br />
cinema.framework<br />
cinema_hybrid.framework<br />
crypt.framework<br />
core.framework<br />
corenodes.framework<br />
command.framework<br />
image.framework<br />
math.framework<br />
misc.framework<br />
mesh_misc.framework<br />
python.framework<br />
)</p>
]]></description><link>http://developers.maxon.net/forum/topic/16444/how-to-find-the-closest-primitive-in-a-mesh</link><generator>RSS for Node</generator><lastBuildDate>Sun, 04 Oct 2026 11:39:10 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/16444.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Sep 2026 19:49:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to find the closest primitive in a mesh on Tue, 29 Sep 2026 19:26:14 GMT]]></title><description><![CDATA[<p dir="auto">First of all, you should open new topics for new questions, as one otherwise tends to derail old topics, which makes it hard to for others to follow things later. I forked your topic.</p>
<p dir="auto">And I also do not quite understand what your question is. <code>GetClosestMeshPrimitive</code> returns you the primitive type via <code>primInfo</code>.</p>
<p dir="auto">When you only want to get the closest point on a mesh, I would build a <a href="https://developers.maxon.net/docs/cpp/2026_3_0/classmaxon_1_1_k_d_tree.html" target="_blank" rel="noopener noreferrer nofollow ugc">KD-Tree</a> for its vertices. You then get the closest vertex and its index for your point <code>p</code>. Then you orthogonally project <code>p</code> onto the polygons attached to that vertex (via <code>cinema:: Neighbor</code>). Then you chose the closest point. We have <a href="https://github.com/Maxon-Computer/Cinema-4D-Python-API-Examples/tree/master/scripts/04_3d_concepts/modeling/kdtree" target="_blank" rel="noopener noreferrer nofollow ugc">this</a> Python example for KDTree and I also used Neighbor there. Building a KD-tree or just brute forcing it depends a bit on how often you want to do it. For just a handful of points, brute forcing it is usually faster.</p>
<p dir="auto">I am sure you can also do this with <code>DistanceQueryInterface</code> and the uvw coordinate returned in the PrimitiveInformation, but all that extra work where you have to deal with all the primitive types seems like more work than it is worth. And when you want to do this in a generator (by the looks of your screens), using a manual KDTree approach will make it easier to parallelize it effectively and make it go zoom zoom instead of computing all that extra data.</p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/77356</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/77356</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Tue, 29 Sep 2026 19:26:14 GMT</pubDate></item><item><title><![CDATA[Reply to How to find the closest primitive in a mesh on Tue, 29 Sep 2026 14:59:13 GMT]]></title><description><![CDATA[<p dir="auto">Thank you Ferdinand.<br />
I have everything working now. The #include &lt;&gt; brackets was just a copy paste thing from the docs. I just had to add the path as you pointed out "maxon/distancequery.h".<br />
One last question about the behavior of<br />
<code>float distance = distanceQuery.GetClosestMeshPrimitive(p, info)</code>.</p>
<p dir="auto">Suppose the user have scaled the polygon mesh using the scale values under the attributes/coordinates. How will this be reflected as a result of the returned distance (assuming the point in the point mesh is first converted to global coordinates and then to local coordinates in the polygon node) like your example above? I see an issue here in my tests where the distance returned is unaffected by the scaling. Either I have done something wrong or the distanceQuery is done on the non "deformed/scaled" mesh.</p>
<p dir="auto">The point generator in this case is not transformed or deformed in any way.</p>
<p dir="auto"><img src="/forum/assets/uploads/files/1790692591623-torus.png" alt="torus.png" class=" img-fluid img-markdown" /> <img src="/forum/assets/uploads/files/1790692591736-torus_scaled.png" alt="torus_scaled.png" class=" img-fluid img-markdown" /> <img src="%5B%5Berror:upload-ratelimit-reached%5D%5D" alt="scale.png" class=" img-fluid img-markdown" /><img src="/forum/assets/uploads/files/1790692729229-scale.png" alt="scale.png" class=" img-fluid img-markdown" /></p>
]]></description><link>http://developers.maxon.net/forum/post/77355</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/77355</guid><dc:creator><![CDATA[dex]]></dc:creator><pubDate>Tue, 29 Sep 2026 14:59:13 GMT</pubDate></item><item><title><![CDATA[Reply to How to find the closest primitive in a mesh on Fri, 18 Sep 2026 08:26:25 GMT]]></title><description><![CDATA[<p dir="auto">Hey <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/dex">@<bdi>dex</bdi></a>,</p>
<p dir="auto"><code>distancequery.h</code> is part of the <a href="https://developers.maxon.net/docs/cpp/2026_3_0/dir_873523e70614bbe4c77aa53dfae02963.html" target="_blank" rel="noopener noreferrer nofollow ugc"><code>mesh_misc.framework</code></a> which you alreeady include. Sounds a bit like you have a corrupted build system on your hands or are not using the frameworks you think you are using. Where does the CMake fragment come from you show us? I assume you are using the old <code>projectdefintion.txt</code> sourced workflow (in which case you should us show that file). Or are you a beta member and have access to the 2027 SDK (which is natively pure CMake), in which case this would be invalid CMake markup, as some stuff has changed.</p>
<p dir="auto">Have you checked in the IDE of your choice that the <code>mesh_misc.framework</code> shows up as a dependency of the project in which you want to <code>#include "maxon/distancequery.h"</code>? And just for the recoord, this is not a std lib, so you cannot use <code>#include &lt;&gt;</code> but must use <code>#include ""</code>. And since this is part of the Maxon API, you also need to specify the <code>maxon</code> folder.</p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/77354</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/77354</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Fri, 18 Sep 2026 08:26:25 GMT</pubDate></item></channel></rss>