Adding UVs to Ngons in C++
-
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?
-
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
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