<?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[Set UVWs for Ngons?]]></title><description><![CDATA[<p dir="auto">For updating the changed UVWs I am using:</p>
<pre><code># Update UV data in Cinema 4D using updated data from RizomUV
def update_uvs_in_cinema4d(doc, obj, poly_sizes, poly_uvw_ids, updated_uvws):
    # Retrieve the active document and object once
    doc, obj = get_active_object()
    if not obj or not isinstance(obj, c4d.PolygonObject):
        gui.MessageDialog("No Polygon Object selected.")
        return

    # Get the Polygon Translation Map
    poly_trans_map = obj.GetPolygonTranslationMap()
    polygon_count, ngon_map = poly_trans_map

    # Detect if there are ngons by checking if the ngonMap contains repeated values
    all_polygons = obj.GetAllPolygons()
    has_ngons = len(set(ngon_map)) != len(ngon_map)
    ngon_count = obj.GetNgonCount()
    print("Number of polygons including polygons inside any ngons: ", len(all_polygons))
    print("Number of polygons including ngons: ",polygon_count)
    print("Number of ngons: ",ngon_count)
    print("Number of internal ngon edges: ",len(ngon_map) - len(set(ngon_map)))

    uvw_tag = obj.GetTag(c4d.Tuvw)
    if not uvw_tag:
        print("No UVW Tag found.")
        return

    doc.SetMode(c4d.Mpolygons)

    handle = c4d.modules.bodypaint.GetActiveUVSet(doc, c4d.GETACTIVEUVSET_ALL)
    if handle is None:
        c4d.CallCommand(170103)  # Open UV editor
        if c4d.API_VERSION &gt;= 22000:
            c4d.modules.bodypaint.UpdateMeshUV(False)

        handle = c4d.modules.bodypaint.GetActiveUVSet(doc, c4d.GETACTIVEUVSET_ALL)
        if handle is None:
            raise RuntimeError("No Active UVSet")

    uv_index = 0
    assembled_uvws = []
    adjusted_uvws = adjust_uvs(updated_uvws)  # Ensure UVs are normalized correctly

    for poly_idx, poly_size in enumerate(poly_sizes):
        uv_dict = {}
        uv_indices = poly_uvw_ids[uv_index:uv_index + poly_size]
        uv_index += poly_size

        # Handle triangles
        if poly_size == 3:
            uv_dict = {
                'c': c4d.Vector(adjusted_uvws[uv_indices[0] * 3], adjusted_uvws[uv_indices[0] * 3 + 1], adjusted_uvws[uv_indices[0] * 3 + 2]),
                'b': c4d.Vector(adjusted_uvws[uv_indices[1] * 3], adjusted_uvws[uv_indices[1] * 3 + 1], adjusted_uvws[uv_indices[1] * 3 + 2]),
                'a': c4d.Vector(adjusted_uvws[uv_indices[2] * 3], adjusted_uvws[uv_indices[2] * 3 + 1], adjusted_uvws[uv_indices[2] * 3 + 2])
            }

        # Handle quads
        elif poly_size == 4:
            uv_dict = {
                'd': c4d.Vector(adjusted_uvws[uv_indices[0] * 3], adjusted_uvws[uv_indices[0] * 3 + 1], adjusted_uvws[uv_indices[0] * 3 + 2]),
                'c': c4d.Vector(adjusted_uvws[uv_indices[1] * 3], adjusted_uvws[uv_indices[1] * 3 + 1], adjusted_uvws[uv_indices[1] * 3 + 2]),
                'b': c4d.Vector(adjusted_uvws[uv_indices[2] * 3], adjusted_uvws[uv_indices[2] * 3 + 1], adjusted_uvws[uv_indices[2] * 3 + 2]),
                'a': c4d.Vector(adjusted_uvws[uv_indices[3] * 3], adjusted_uvws[uv_indices[3] * 3 + 1], adjusted_uvws[uv_indices[3] * 3 + 2])
            }

        # Handle ngons (polygons with more than 4 vertices)
        elif has_ngons:
            # Sort the vertices properly and create the UV dict dynamically
            alphabet = 'abcdefghijklmnopqrstuvwxyz'
            for i in range(poly_size):
                # Make sure to use the correct UV order
                key = alphabet[i] if i &lt; len(alphabet) else f'v{i}'  # Handle large ngons
                uv_dict[key] = c4d.Vector(
                    adjusted_uvws[uv_indices[i] * 3],
                    adjusted_uvws[uv_indices[i] * 3 + 1],
                    adjusted_uvws[uv_indices[i] * 3 + 2]
                )

        assembled_uvws.append(uv_dict)

    handle.SetUVWFromTextureView(assembled_uvws, True, True, True)
    bodypaint.FreeActiveUVSet(handle)
    c4d.EventAdd()
</code></pre>
<p dir="auto">My problem is, it works with a mesh that is only quads and tris or any combination thereof, but if the mesh contains any ngons then I get this result:<br />
<img src="/forum/assets/uploads/files/1727982214709-issue.png" alt="Issue.PNG" class=" img-fluid img-markdown" /></p>
]]></description><link>http://developers.maxon.net/forum/topic/15747/set-uvws-for-ngons</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 06:52:53 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/15747.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Oct 2024 19:35:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Set UVWs for Ngons? on Tue, 10 Dec 2024 16:43:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/ferdinand">@<bdi>ferdinand</bdi></a> I figured this issue out so you can mark this as solved/closed. Thank you.</p>
]]></description><link>http://developers.maxon.net/forum/post/75465</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/75465</guid><dc:creator><![CDATA[ELJeffery]]></dc:creator><pubDate>Tue, 10 Dec 2024 16:43:09 GMT</pubDate></item><item><title><![CDATA[Reply to Set UVWs for Ngons? on Mon, 07 Oct 2024 18:21:05 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/eljeffery">@<bdi>ELJeffery</bdi></a>,</p>
<p dir="auto">Welcome to the Maxon developers forum and its community, it is great to have you with us!</p>
<h4>Getting Started</h4>
<p dir="auto">Before creating your next postings, we would recommend making yourself accustomed with our forum and support procedures. You did not do anything wrong, we point all new users to these rules.</p>
<ul>
<li><a href="/forum/topic/15242/">Forum Overview</a>: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.</li>
<li><a href="/forum/topic/15244/">Support Procedures</a>: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.</li>
<li><a href="/forum/topic/15243/">Forum Features</a>: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.</li>
</ul>
<p dir="auto">It is <strong>strongly</strong> recommended to read the first two topics carefully, especially the section <a href="/forum/topic/15244/">Support Procedures: Asking Questions</a>.</p>
<h4>About your First Question</h4>
<p dir="auto">Please have a look at <a href="https://developers.maxon.net/forum/topic/15244/support-procedures/3" target="_blank" rel="noopener noreferrer nofollow ugc">Support Procedures: How to Ask Questions</a>, specifically in the context of repeatability. We cannot run your code as it is not executable as it is lacking things like imports and also some logic, e.g. <code>adjust_uvs</code>. Otherwise answering your question is pure guess work for us. Please also explain in one to two sentences what you want to achieve. "Updating" uv data is a very broad term. Until there some clarity and executable code, that is unfortunately all I can say.</p>
<p dir="auto">Cheers,<br />
Ferdinand</p>
]]></description><link>http://developers.maxon.net/forum/post/75076</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/75076</guid><dc:creator><![CDATA[ferdinand]]></dc:creator><pubDate>Mon, 07 Oct 2024 18:21:05 GMT</pubDate></item><item><title><![CDATA[Reply to Set UVWs for Ngons? on Thu, 03 Oct 2024 19:37:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/eljeffery">@<bdi>ELJeffery</bdi></a><br />
The image:<br />
<img src="/forum/assets/uploads/files/1727984237795-issue.png" alt="Issue.PNG" class=" img-fluid img-markdown" /></p>
]]></description><link>http://developers.maxon.net/forum/post/75066</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/75066</guid><dc:creator><![CDATA[ELJeffery]]></dc:creator><pubDate>Thu, 03 Oct 2024 19:37:24 GMT</pubDate></item></channel></rss>