Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Adding UVs to Ngons in C++

    Cinema 4D SDK
    c++ 2024
    2
    2
    371
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mn-kb3d
      last edited by

      Hello!

      I'm currently working on an importer using C++. I want to support importing meshes with faces that can be tris, quads, and ngons.

      I'm currently able to construct the mesh by using the Modeling class and constructing each face as an "ngon" by doing the following:

      modeling->CreateNgon(polyObj, faceIndexList.data(), faceIndexList.size());
      

      where faceIndexList contains a list of points that make up that face.

      The final thing I need to do is to add UVs to the constructed mesh. For faces with tris and quads, this is no problem using UVWTag and UVWStruct.

      The issue comes in when trying add UVs for faces with a number of points greater than 4. I'm not quite sure how I would go about constructing a UVWStruct object for a face with 5 points, for example.

      I feel like the move is to not use a UVWTag here, but I'm not quite sure what my alternatives are. Is there a way to directly set the UV of a specific point in a mesh? Or is this a candidate for a CustomDataTag?

      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @mn-kb3d
        last edited by ferdinand

        Hello @mn-kb3d ,

        Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!

        Getting Started

        Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:

        • Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
        • Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
        • Forum Structure and Features: Lines out how the forum works.
        • Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.

        About your First Question

        Sorry for the delayed answer.

        In your further postings please add a code snippet that highlights the issue you're struggling with and shows the context of your question.

        Please also note that you're pointing out to the outdated documentation, please use the up-to-date one instead: UVWStruct. You can easily access it from the top menu as shown on the screenshot
        a17b9e9f-6762-4617-ae84-9d0fe94c73cd-image.png

        Regarding your question. Ngons are actually sort of a collection of polygons (tris or quads). Even though you create an Ngon, for the UV mapping you would be using the same UVWStruct being applied to the underlying polygons.

        To find out the corresponding polygons and its indices you're welcome to use GetPolygonTranslationMap and GetNGonTranslationMap functions. Here is a simple example of how you can use them:

        // PolygonObject* poly;
        // ...
        // // Polygon-object initialization routine
        // ...
        Int32 ngonCount = 0;
        Int32* polyMap = nullptr;
        CheckState(poly->GetPolygonTranslationMap(ngonCount, polyMap));
        Int32** ngons = nullptr;
        CheckState(poly->GetNGonTranslationMap(ngonCount, polyMap, ngons));
        
        for (Int32 i = 0; i < ngonCount; ++i)
        {
        	Int32 nPoly = ngons[i][0];
        	String polyIndicesStr;
        	for (Int32 j = 1; j < nPoly + 1; ++j)
        		polyIndicesStr += FormatString("@ ", polygonIdx);
        	DiagnosticOutput("Ngon #@ with @ polygons: @", i, nPoly, polyIndicesStr);
        }
        

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • First post
          Last post