KDZ Handling polygons with +4 sides?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/07/2004 at 15:30, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 8.503
Platform: Windows ;
Language(s) : C++ ;---------
It has come to my attention that some Wavefront OBJ files that I'm importing with my plugin have polygons with more than 4 sides. Since C4D does not use n-gons, please suggest a course of action.Thank you,
Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 03:27, xxxxxxxx wrote:
Triangulate the mesh?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 06:23, xxxxxxxx wrote:
Yeah, but not sure how to proceed. On import, I create a PolygonObject with the correct number of the polygons to contain all of them in the file. Otherwise, I have to know a way to ADD polygons to the PolygonObject. So, I thought that maybe there was a way to let C4D do the triangulation.
How do you add polygons to a PolygonObject?
Thanks,
Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 06:28, xxxxxxxx wrote:
You can use ResizeObject for this. (specify the positions for the new points and create a polygon with the Polygon Class for example).
There are some triangulation functions in the SDK too that you may use.
Samir -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 08:34, xxxxxxxx wrote:
Excellent! So focused on something like 'AddPolygon', didn't even see that method!
Does resizing have any effect on existing polygons (such as point assignments)?
Thanks Samir!
Robert
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 11:09, xxxxxxxx wrote:
Hmm, I couldn´t encounter any side effects on existing polygons (the allocated new indices are attached to the end of the array, so existing ones shouldn´t be touched by this. If you want to insert points/polygons inbetween you probably won´t get around the VariableChanged class. There should also be an example in the SDK)
Have fun! -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 16:10, xxxxxxxx wrote:
Another option would be to pre-process the file to find out how many polys you will actually need, then allocate a PolygonObject of the correct size, then process the file contents a second time as you actually generate the polys.
Doesn't really matter which option you go for, it's a matter of preference mainly.
Cheers - Steve
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 17:54, xxxxxxxx wrote:
Actually, I'm already doing this. So, I have the number of polygons listed in the file (if they weren't n-gons). I'd have to count each of the vertex sets after the 'f' and determine the number of additional polygons needed for each n-gon encountered (2 for 5v, 3 for 6v, etc.). That's a possibility.
Thanks,
Robert -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 13/07/2004 at 20:25, xxxxxxxx wrote:
Aye, I'm doing the same thing... I scan the file once and get all the counts I need, allocate my buffers, then parse the file again reading the values. For n-gons, I cut it up into a quad, then an additional triangle per vertex above 4, so when I'm scanning the file, my logic counts vertices (that make up the polys) and bumps my poly count by vCount - 4 for any that are > 4.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/07/2004 at 09:25, xxxxxxxx wrote:
Actually, I found it simpler to cut the n-gon into quads, being left with a triangle in odd number cases. C4D's approach is rather nerve-wracking. Whereas the polygon vertices are straightforward indices into a vertex array, the UVWs are store as a polygon directly, without indices, but actual data. Therefore, I have to set indices for geometry (easy enough) and fill vectors for UVWs. Very disconcerting. ;/
So, here's what I do (and I've done this before, but, for the life of me, cannot find the 'triangulation' code that I worked out in the past) :
In the first pass, count all of the vertices in each polygon and determine the number of C4D polygons to result with:
fnum += ((n + (n % 2)) / 2) - 1;
where 'n' is the number of vertex indices for the polygon and 'fnum' is a running total of polygons for the object. This works for triangles, quads, and n-gons.
Next, I retrieve the first point (v/vt) for use during subdivision. Subdivision proceeds as standard:
0 1 2 3 [P = 3]
0 3 4 5 [P = 5]
0 5 6 7 [P = 7]
...
0 P P+1 P+2 (triangle; 0 P P+1 P+1)// Parse facet vertex indices -- NOTE: 5+ sided polygons will be subdivided newFacet = FALSE; // Get First v/vt indices if ((token = tokenreader->GetToken(NULL, DELIM_SPACES)) != NULL) { strcpy(point, token); v0 = (LONG)atol(subreader->GetToken(point, DELIM_FACET)); if (v0 > 0) v0--; else v0 = vnum + v0; *polyindx = v0; polyindx++; if ((token = subreader->GetToken(NULL, DELIM_FACET)) != NULL) { vt0 = (LONG)atol(token); if (vt0 > 0) vt0--; else vt0 = vtnum + vt0; uvws->x = UVWs[vt0].x; uvws->y = UVWs[vt0].y; uvws->z = UVWs[vt0].z; uvws++; } } while ((token = tokenreader->GetToken(NULL, DELIM_SPACES)) != NULL) { // preprocess subdivided n-gon if (newFacet) { *polyindx = v0; polyindx++; *polyindx = vN; polyindx++; uvws->x = UVWs[vt0].x; uvws->y = UVWs[vt0].y; uvws->z = UVWs[vt0].z; uvws++; uvws->x = UVWs[vtN].x; uvws->y = UVWs[vtN].y; uvws->z = UVWs[vtN].z; uvws++; newFacet = FALSE; } strcpy(point, token); *polyindx = (LONG)atol(subreader->GetToken(point, DELIM_FACET)); if (*polyindx > 0) (*polyindx)--; else *polyindx = vnum + *polyindx; if ((token = subreader->GetToken(NULL, DELIM_FACET)) != NULL) { p = (LONG)atol(token); if (p > 0) p--; else p = vtnum + p; uvws->x = UVWs .x; uvws->y = UVWs .y; uvws->z = UVWs .z; if (uvws == &(uvwstruct.d)) { // Add UV polygon uvwTag->Set(fnum, uvwstruct); uvws = &(uvwstruct.a); vtN = p; } else uvws++; } if (polyindx == &(polygon->d)) { // Add polygon to Group SelectionTag gmtG->AddPolygon(fnum); // Add polygon to Material SelectionTag gmtM->AddPolygon(fnum); vN = *polyindx; fnum++; polygon++; polyindx = &(polygon->a); newFacet = TRUE; } else polyindx++; } // Handle [Final] Triangles if (polyindx == &(polygon->d)) { polygon->d = polygon->c; uvwstruct.d.x = uvwstruct.c.x; uvwstruct.d.y = uvwstruct.c.y; uvwstruct.d.z = uvwstruct.c.z; // Add polygon to Group SelectionTag gmtG->AddPolygon(fnum); // Add polygon to Material SelectionTag gmtM->AddPolygon(fnum); // Add UV polygon uvwTag->Set(fnum, uvwstruct); // update indices uvws = &(uvwstruct.a); polygon++; polyindx = &(polygon->a); fnum++; }
Kuroyume
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/07/2004 at 10:18, xxxxxxxx wrote:
I assume that the reason that UVW data is stored per poly, is so that polys can be textured totally independently from each other, which would not be the case if the UVWs were assigned to vertices.
Cheers - Steve